From a90fae56962a2a5c67ab4302627b285c22ef638d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 10 Nov 2021 18:08:45 +0900 Subject: [PATCH] fix(swc): Fix tests (#2707) --- .github/workflows/cargo.yml | 7 + .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 49 ++++- .../input.ts/es5.2.minified/output.js | 82 ++++--- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 55 ++++- .../input.ts/es5.2.minified/output.js | 93 +++++--- .../input.ts/es5.1.normal/output.js | 45 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 76 +++++-- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 42 +++- .../input.ts/es5.1.normal/output.js | 32 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 34 ++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 45 +++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 49 ++++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 53 ++++- .../input.ts/es5.2.minified/output.js | 66 ++++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 42 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 42 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 42 +++- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 45 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 54 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 42 +++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 51 ++++- .../input.ts/es5.2.minified/output.js | 54 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 55 +++-- .../input.ts/es5.2.minified/output.js | 56 +++-- .../input.ts/es5.1.normal/output.js | 55 ++++- .../input.ts/es5.2.minified/output.js | 94 +++++--- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 55 +++-- .../input.ts/es5.2.minified/output.js | 56 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 48 +++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 48 +++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 51 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 42 +++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 44 +++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 42 +++- .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 46 +++- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 32 +++ .../input.ts/es5.2.minified/output.js | 19 +- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 34 ++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 34 ++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 65 ++++-- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 65 ++++-- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 33 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 33 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 33 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 44 +++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 44 +++- .../input.ts/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 57 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 36 ++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 49 ++++- .../input.ts/es5.2.minified/output.js | 49 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 58 ++++- .../input.ts/es5.2.minified/output.js | 100 ++++++--- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 64 ++++-- .../input.ts/es5.1.normal/output.js | 58 ++++- .../input.ts/es5.2.minified/output.js | 100 ++++++--- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 43 +++- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 43 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 45 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 45 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 45 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 45 +++- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 47 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 43 +++- .../input.tsx/es5.2.minified/output.js | 70 ++++-- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 46 ++-- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 28 ++- .../input.tsx/es5.2.minified/output.js | 44 +++- .../input.tsx/es5.1.normal/output.js | 37 +++- .../input.tsx/es5.2.minified/output.js | 58 +++-- .../input.tsx/es5.1.normal/output.js | 37 +++- .../input.tsx/es5.2.minified/output.js | 58 +++-- .../input.tsx/es5.1.normal/output.js | 31 ++- .../input.tsx/es5.2.minified/output.js | 47 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 42 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 63 ++++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 43 +++- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 45 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 60 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 40 +++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 44 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 34 ++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 38 +++- .../input.ts/es5.2.minified/output.js | 41 +++- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 37 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 41 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 50 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 112 +++++++--- .../input.ts/es5.2.minified/output.js | 208 ++++++++++++------ .../input.ts/es5.1.normal/output.js | 52 ++++- .../input.ts/es5.2.minified/output.js | 88 +++++--- .../input.ts/es5.1.normal/output.js | 79 +++++-- .../input.ts/es5.2.minified/output.js | 142 ++++++++---- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 58 +++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 76 +++++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 61 +++-- .../input.ts/es5.2.minified/output.js | 88 +++++--- .../input.ts/es5.1.normal/output.js | 47 +++- .../input.ts/es5.2.minified/output.js | 62 ++++-- .../input.ts/es5.1.normal/output.js | 47 +++- .../input.ts/es5.2.minified/output.js | 62 ++++-- .../input.ts/es5.1.normal/output.js | 56 ++++- .../input.ts/es5.2.minified/output.js | 80 ++++--- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 70 ++++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 76 +++++-- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 91 ++++++-- .../input.ts/es5.2.minified/output.js | 166 +++++++++----- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 44 +++- .../input.ts/es5.2.minified/output.js | 56 +++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 39 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- .../input.ts/es5.1.normal/output.js | 44 +++- .../input.ts/es5.2.minified/output.js | 56 +++-- .../input.ts/es5.1.normal/output.js | 43 +++- .../input.ts/es5.2.minified/output.js | 52 +++-- .../input.ts/es5.1.normal/output.js | 45 +++- .../input.ts/es5.2.minified/output.js | 54 +++-- .../input.ts/es5.1.normal/output.js | 46 +++- .../input.ts/es5.2.minified/output.js | 49 +++-- .../input.ts/es5.1.normal/output.js | 49 ++++- .../input.ts/es5.2.minified/output.js | 56 +++-- .../input.ts/es5.1.normal/output.js | 28 ++- .../input.ts/es5.2.minified/output.js | 40 +++- .../input.ts/es5.1.normal/output.js | 31 ++- .../input.ts/es5.2.minified/output.js | 46 ++-- crates/swc/tests/tsc.rs | 8 +- crates/testing_macros/src/fixture.rs | 4 + ecmascript/minifier/tests/mangle.rs | 1 - ecmascript/parser/tests/comments.rs | 2 - ecmascript/parser/tests/span.rs | 1 - 803 files changed, 26062 insertions(+), 6595 deletions(-) diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index 99f35a9fed9..8432d3874f6 100644 --- a/.github/workflows/cargo.yml +++ b/.github/workflows/cargo.yml @@ -69,6 +69,13 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Checkout submodules + shell: bash + run: | + auth_header="$(git config --local --get http.https://github.com/.extraheader)" + git submodule sync --recursive + git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + # We explicitly do this to cache properly. - name: Install Rust uses: actions-rs/toolchain@v1 diff --git a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.1.normal/output.js index 8084bbf35f2..3ae54fae254 100644 --- a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.1.normal/output.js @@ -179,6 +179,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -202,9 +227,10 @@ var A = // @target: es6 var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super1 = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super1.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.2.minified/output.js index de0fe3e6312..0e50c39d102 100644 --- a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuperConflict_es6/input.ts/es5.2.minified/output.js @@ -112,14 +112,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -128,7 +121,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super1 = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super1.apply(this, arguments); + } + return _createClass(B, [ { key: "simple", value: function() { diff --git a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.1.normal/output.js index 78c02831a8b..9262bcb20e2 100644 --- a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.1.normal/output.js @@ -179,6 +179,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: es2017 // @noEmitHelpers: true /*#__PURE__*/ function() { @@ -203,9 +228,10 @@ var A = // @target: es2017 var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.2.minified/output.js index d10648f12c4..cfe65155cb3 100644 --- a/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/asyncMethodWithSuper_es2017/input.ts/es5.2.minified/output.js @@ -112,14 +112,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -128,7 +121,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "simple", value: function() { diff --git a/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.1.normal/output.js index cd589095839..c392977a225 100644 --- a/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.1.normal/output.js @@ -74,6 +74,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function _func() { _func = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var D; @@ -83,9 +108,10 @@ function _func() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D, _super); + var _super1 = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super1.apply(this, arguments); } return D; }; diff --git a/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.2.minified/output.js index 6c8445798a5..236d0a3d017 100644 --- a/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es2017/awaitClassExpression_es2017/input.ts/es5.2.minified/output.js @@ -26,20 +26,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function _func() { return (_func = (function(fn) { return function() { @@ -62,10 +77,12 @@ function _func() { case 0: return _ctx.t0 = function(_super) { "use strict"; + _inherits(D, _super); + var _super1 = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super1.apply(this, arguments); } - return _inherits(D, _super), D; + return D; }, _ctx.next = 3, p; case 3: _ctx.t1 = _ctx.sent, D = (0, _ctx.t0)(_ctx.t1); diff --git a/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.1.normal/output.js index 988f98e1e90..e18074c203f 100644 --- a/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.1.normal/output.js @@ -146,6 +146,31 @@ function _wrapNativeSuper(Class) { }; return _wrapNativeSuper(Class); } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: es5 // @lib: es5,es2015.promise // @module: commonjs @@ -153,9 +178,10 @@ function _wrapNativeSuper(Class) { export var Task = /*#__PURE__*/ function(Promise) { "use strict"; _inherits(Task, Promise); + var _super = _createSuper(Task); function Task() { _classCallCheck(this, Task); - return _possibleConstructorReturn(this, _getPrototypeOf(Task).apply(this, arguments)); + return _super.apply(this, arguments); } return Task; }(_wrapNativeSuper(Promise)); diff --git a/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.2.minified/output.js index 74c517c2d83..be6c8ca1d83 100644 --- a/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es5/asyncImportedPromise_es5/input.ts/es5.2.minified/output.js @@ -72,14 +72,7 @@ function _wrapNativeSuper(Class) { } export var _typeof, Task = function(Promise) { "use strict"; - function Task() { - var self, call, obj; - return _classCallCheck(this, Task), self = this, call = _getPrototypeOf(Task).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -88,7 +81,35 @@ export var _typeof, Task = function(Promise) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Task, Promise), Task; + }(Task, Promise); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Task); + function Task() { + return _classCallCheck(this, Task), _super.apply(this, arguments); + } + return Task; }(_wrapNativeSuper(Promise)); var Test = function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.1.normal/output.js index 8765b536e11..27a0d3de7de 100644 --- a/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.1.normal/output.js @@ -179,6 +179,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: ES5 // @lib: es5,es2015.promise // @noEmitHelpers: true @@ -204,9 +229,10 @@ var A = // @target: ES5 var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.2.minified/output.js index d10648f12c4..cfe65155cb3 100644 --- a/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es5/asyncMethodWithSuper_es5/input.ts/es5.2.minified/output.js @@ -112,14 +112,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -128,7 +121,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "simple", value: function() { diff --git a/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.1.normal/output.js index cd589095839..c392977a225 100644 --- a/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.1.normal/output.js @@ -74,6 +74,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function _func() { _func = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var D; @@ -83,9 +108,10 @@ function _func() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D, _super); + var _super1 = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super1.apply(this, arguments); } return D; }; diff --git a/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.2.minified/output.js index 6c8445798a5..236d0a3d017 100644 --- a/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es5/awaitClassExpression_es5/input.ts/es5.2.minified/output.js @@ -26,20 +26,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function _func() { return (_func = (function(fn) { return function() { @@ -62,10 +77,12 @@ function _func() { case 0: return _ctx.t0 = function(_super) { "use strict"; + _inherits(D, _super); + var _super1 = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super1.apply(this, arguments); } - return _inherits(D, _super), D; + return D; }, _ctx.next = 3, p; case 3: _ctx.t1 = _ctx.sent, D = (0, _ctx.t0)(_ctx.t1); diff --git a/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.1.normal/output.js index c22f8efe52a..0bb1afc0319 100644 --- a/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.1.normal/output.js @@ -146,15 +146,41 @@ function _wrapNativeSuper(Class) { }; return _wrapNativeSuper(Class); } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: es6 // @module: commonjs // @filename: task.ts export var Task = /*#__PURE__*/ function(Promise) { "use strict"; _inherits(Task, Promise); + var _super = _createSuper(Task); function Task() { _classCallCheck(this, Task); - return _possibleConstructorReturn(this, _getPrototypeOf(Task).apply(this, arguments)); + return _super.apply(this, arguments); } return Task; }(_wrapNativeSuper(Promise)); diff --git a/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.2.minified/output.js index 74c517c2d83..be6c8ca1d83 100644 --- a/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es6/asyncImportedPromise_es6/input.ts/es5.2.minified/output.js @@ -72,14 +72,7 @@ function _wrapNativeSuper(Class) { } export var _typeof, Task = function(Promise) { "use strict"; - function Task() { - var self, call, obj; - return _classCallCheck(this, Task), self = this, call = _getPrototypeOf(Task).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -88,7 +81,35 @@ export var _typeof, Task = function(Promise) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Task, Promise), Task; + }(Task, Promise); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Task); + function Task() { + return _classCallCheck(this, Task), _super.apply(this, arguments); + } + return Task; }(_wrapNativeSuper(Promise)); var Test = function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.1.normal/output.js index af3141e8fc4..896fded635b 100644 --- a/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.1.normal/output.js @@ -268,6 +268,31 @@ function _wrapAsyncGenerator(fn) { return new AsyncGenerator(fn.apply(this, arguments)); }; } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: ES6 // @lib: esnext // @noEmitHelpers: true @@ -293,9 +318,10 @@ var A = // @target: ES6 var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.2.minified/output.js index 73db0654ebb..8b6df50ef45 100644 --- a/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es6/asyncMethodWithSuper_es6/input.ts/es5.2.minified/output.js @@ -180,14 +180,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -196,7 +189,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "simple", value: function() { diff --git a/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.1.normal/output.js index cd589095839..c392977a225 100644 --- a/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.1.normal/output.js @@ -74,6 +74,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function _func() { _func = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var D; @@ -83,9 +108,10 @@ function _func() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D, _super); + var _super1 = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super1.apply(this, arguments); } return D; }; diff --git a/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.2.minified/output.js index 6c8445798a5..236d0a3d017 100644 --- a/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/async/es6/awaitClassExpression_es6/input.ts/es5.2.minified/output.js @@ -26,20 +26,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function _func() { return (_func = (function(fn) { return function() { @@ -62,10 +77,12 @@ function _func() { case 0: return _ctx.t0 = function(_super) { "use strict"; + _inherits(D, _super); + var _super1 = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super1.apply(this, arguments); } - return _inherits(D, _super), D; + return D; }, _ctx.next = 3, p; case 3: _ctx.t1 = _ctx.sent, D = (0, _ctx.t0)(_ctx.t1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.1.normal/output.js index 5956f85bab2..9f20fd3cde9 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.2.minified/output.js index 69ab5df793a..f01c26ec4e7 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability/input.ts/es5.2.minified/output.js @@ -16,33 +16,53 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), C; + return C; }(B); new B, new A1, new B; diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.1.normal/output.js index 38c0a579a66..c6fc87d36f2 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -75,36 +100,40 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); var D = /*#__PURE__*/ function(B) { "use strict"; _inherits(D, B); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(B); var E = /*#__PURE__*/ function(B) { "use strict"; _inherits(E, B); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.2.minified/output.js index 1c553053e25..a73a1f4ff25 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractExtends/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -52,28 +68,36 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), C; + return C; }(B), D = function(B) { "use strict"; + _inherits(D, B); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, B), D; + return D; }(B), E = function(B) { "use strict"; + _inherits(E, B); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, B), _createClass(E, [ + return _createClass(E, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.1.normal/output.js index 3695d6f5d82..0943a01ce1c 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,9 +76,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.2.minified/output.js index 5d3123e1f01..a3c33b10381 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var A1 = function() { _classCallCheck(this, A1); }, B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return B; }(A1); function NewA(Factory) { return new A1; diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.1.normal/output.js index 3532250f01e..b36a6df0329 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -65,18 +90,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; } // error -- inherits abstract methods @@ -84,9 +111,10 @@ var C = /*#__PURE__*/ function(A) { var D = /*#__PURE__*/ function(A) { "use strict"; _inherits(D, A); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; } // error -- inherits abstract methods @@ -94,9 +122,10 @@ var D = /*#__PURE__*/ function(A) { var E = /*#__PURE__*/ function(A) { "use strict"; _inherits(E, A); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { @@ -111,9 +140,10 @@ var E = /*#__PURE__*/ function(A) { var F = /*#__PURE__*/ function(A) { "use strict"; _inherits(F, A); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); - return _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(F, [ { @@ -127,9 +157,10 @@ var F = /*#__PURE__*/ function(A) { var G = /*#__PURE__*/ function(A) { "use strict"; _inherits(G, A); + var _super = _createSuper(G); function G() { _classCallCheck(this, G); - return _possibleConstructorReturn(this, _getPrototypeOf(G).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(G, [ { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.2.minified/output.js index 6e4742f5598..9e65aaa356e 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractGeneric/input.ts/es5.2.minified/output.js @@ -25,46 +25,70 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), C; + return C; }(A1), D = function(A) { "use strict"; + _inherits(D, A); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, A), D; + return D; }(A1), E = function(A) { "use strict"; + _inherits(E, A); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, A), _createClass(E, [ + return _createClass(E, [ { key: "foo", value: function() { @@ -74,10 +98,12 @@ var _typeof = function(obj) { ]), E; }(A1), F = function(A) { "use strict"; + _inherits(F, A); + var _super = _createSuper(F); function F() { - return _classCallCheck(this, F), _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _classCallCheck(this, F), _super.apply(this, arguments); } - return _inherits(F, A), _createClass(F, [ + return _createClass(F, [ { key: "bar", value: function(t) { @@ -86,10 +112,12 @@ var _typeof = function(obj) { ]), F; }(A1), G = function(A) { "use strict"; + _inherits(G, A); + var _super = _createSuper(G); function G() { - return _classCallCheck(this, G), _possibleConstructorReturn(this, _getPrototypeOf(G).apply(this, arguments)); + return _classCallCheck(this, G), _super.apply(this, arguments); } - return _inherits(G, A), _createClass(G, [ + return _createClass(G, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.1.normal/output.js index 7b163408991..b5c9b8ac91f 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var M1; (function(M) { var A = function A() { @@ -54,9 +79,10 @@ var M1; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.2.minified/output.js index cabaf246da6..ca182005d1c 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule/input.ts/es5.2.minified/output.js @@ -20,14 +20,7 @@ function _setPrototypeOf(o, p) { M.A = A1; var B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return (function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +29,35 @@ function _setPrototypeOf(o, p) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - })(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return B; }(A1); M.B = B; }(M1 || (M1 = { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.1.normal/output.js index d5d1929994f..02bf050182e 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); @@ -73,54 +100,60 @@ var AA = function AA() { var BB = /*#__PURE__*/ function(AA) { "use strict"; _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { _classCallCheck(this, BB); - return _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _super.apply(this, arguments); } return BB; }(AA); var CC = /*#__PURE__*/ function(AA) { "use strict"; _inherits(CC, AA); + var _super = _createSuper(CC); function CC() { _classCallCheck(this, CC); - return _possibleConstructorReturn(this, _getPrototypeOf(CC).apply(this, arguments)); + return _super.apply(this, arguments); } return CC; }(AA); var DD = /*#__PURE__*/ function(BB) { "use strict"; _inherits(DD, BB); + var _super = _createSuper(DD); function DD() { _classCallCheck(this, DD); - return _possibleConstructorReturn(this, _getPrototypeOf(DD).apply(this, arguments)); + return _super.apply(this, arguments); } return DD; }(BB); var EE = /*#__PURE__*/ function(BB) { "use strict"; _inherits(EE, BB); + var _super = _createSuper(EE); function EE() { _classCallCheck(this, EE); - return _possibleConstructorReturn(this, _getPrototypeOf(EE).apply(this, arguments)); + return _super.apply(this, arguments); } return EE; }(BB); var FF = /*#__PURE__*/ function(CC) { "use strict"; _inherits(FF, CC); + var _super = _createSuper(FF); function FF() { _classCallCheck(this, FF); - return _possibleConstructorReturn(this, _getPrototypeOf(FF).apply(this, arguments)); + return _super.apply(this, arguments); } return FF; }(CC); var GG = /*#__PURE__*/ function(CC) { "use strict"; _inherits(GG, CC); + var _super = _createSuper(GG); function GG() { _classCallCheck(this, GG); - return _possibleConstructorReturn(this, _getPrototypeOf(GG).apply(this, arguments)); + return _super.apply(this, arguments); } return GG; }(CC); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.2.minified/output.js index 27c1cd5ae9c..f026ca8cb01 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInheritance/input.ts/es5.2.minified/output.js @@ -16,71 +16,103 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), C; + return C; }(A1), AA1 = function() { "use strict"; _classCallCheck(this, AA1); }, BB = function(AA) { "use strict"; + _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { - return _classCallCheck(this, BB), _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _classCallCheck(this, BB), _super.apply(this, arguments); } - return _inherits(BB, AA), BB; + return BB; }(AA1), CC = function(AA) { "use strict"; + _inherits(CC, AA); + var _super = _createSuper(CC); function CC() { - return _classCallCheck(this, CC), _possibleConstructorReturn(this, _getPrototypeOf(CC).apply(this, arguments)); + return _classCallCheck(this, CC), _super.apply(this, arguments); } - return _inherits(CC, AA), CC; + return CC; }(AA1), DD = function(BB) { "use strict"; + _inherits(DD, BB); + var _super = _createSuper(DD); function DD() { - return _classCallCheck(this, DD), _possibleConstructorReturn(this, _getPrototypeOf(DD).apply(this, arguments)); + return _classCallCheck(this, DD), _super.apply(this, arguments); } - return _inherits(DD, BB), DD; + return DD; }(BB), EE = function(BB) { "use strict"; + _inherits(EE, BB); + var _super = _createSuper(EE); function EE() { - return _classCallCheck(this, EE), _possibleConstructorReturn(this, _getPrototypeOf(EE).apply(this, arguments)); + return _classCallCheck(this, EE), _super.apply(this, arguments); } - return _inherits(EE, BB), EE; + return EE; }(BB), FF = function(CC) { "use strict"; + _inherits(FF, CC); + var _super = _createSuper(FF); function FF() { - return _classCallCheck(this, FF), _possibleConstructorReturn(this, _getPrototypeOf(FF).apply(this, arguments)); + return _classCallCheck(this, FF), _super.apply(this, arguments); } - return _inherits(FF, CC), FF; + return FF; }(CC), GG = function(CC) { "use strict"; + _inherits(GG, CC); + var _super = _createSuper(GG); function GG() { - return _classCallCheck(this, GG), _possibleConstructorReturn(this, _getPrototypeOf(GG).apply(this, arguments)); + return _classCallCheck(this, GG), _super.apply(this, arguments); } - return _inherits(GG, CC), GG; + return GG; }(CC); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.1.normal/output.js index 52171c85c0d..571735426a6 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.2.minified/output.js index 958a7d49834..641a46f4a15 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations1/input.ts/es5.2.minified/output.js @@ -16,33 +16,53 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), C; + return C; }(B); new A1, new A1(1), new B, new C, new B, new B, new B; diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.1.normal/output.js index 37f0ecc3a11..1fb3da41cb1 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -75,9 +100,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -98,9 +124,10 @@ var AA = /*#__PURE__*/ function() { var BB = /*#__PURE__*/ function(AA) { "use strict"; _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { _classCallCheck(this, BB); - return _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(BB, [ { @@ -114,9 +141,10 @@ var BB = /*#__PURE__*/ function(AA) { var CC = /*#__PURE__*/ function(BB) { "use strict"; _inherits(CC, BB); + var _super = _createSuper(CC); function CC() { _classCallCheck(this, CC); - return _possibleConstructorReturn(this, _getPrototypeOf(CC).apply(this, arguments)); + return _super.apply(this, arguments); } return CC; } // error @@ -124,9 +152,10 @@ var CC = /*#__PURE__*/ function(BB) { var DD = /*#__PURE__*/ function(BB) { "use strict"; _inherits(DD, BB); + var _super = _createSuper(DD); function DD() { _classCallCheck(this, DD); - return _possibleConstructorReturn(this, _getPrototypeOf(DD).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(DD, [ { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.2.minified/output.js index 4da46b21c56..a7911112f2a 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractOverrideWithAbstract/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -52,10 +68,12 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A), AA = function() { "use strict"; function AA() { @@ -70,10 +88,12 @@ var _typeof = function(obj) { ]), AA; }(), BB = function(AA) { "use strict"; + _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { - return _classCallCheck(this, BB), _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _classCallCheck(this, BB), _super.apply(this, arguments); } - return _inherits(BB, AA), _createClass(BB, [ + return _createClass(BB, [ { key: "bar", value: function() { @@ -82,16 +102,20 @@ var _typeof = function(obj) { ]), BB; }(AA), CC = function(BB) { "use strict"; + _inherits(CC, BB); + var _super = _createSuper(CC); function CC() { - return _classCallCheck(this, CC), _possibleConstructorReturn(this, _getPrototypeOf(CC).apply(this, arguments)); + return _classCallCheck(this, CC), _super.apply(this, arguments); } - return _inherits(CC, BB), CC; + return CC; }(BB), DD = function(BB) { "use strict"; + _inherits(DD, BB); + var _super = _createSuper(DD); function DD() { - return _classCallCheck(this, DD), _possibleConstructorReturn(this, _getPrototypeOf(DD).apply(this, arguments)); + return _classCallCheck(this, DD), _super.apply(this, arguments); } - return _inherits(DD, BB), _createClass(DD, [ + return _createClass(DD, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.1.normal/output.js index dc620c0bc84..3380142983e 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -99,9 +124,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -122,9 +148,10 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { @@ -172,9 +199,10 @@ var AA = /*#__PURE__*/ function() { var BB = /*#__PURE__*/ function(AA) { "use strict"; _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { _classCallCheck(this, BB); - return _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _super.apply(this, arguments); } return BB; }(AA); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.2.minified/output.js index 11c3dd558b8..5d3086f587e 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractSuperCalls/input.ts/es5.2.minified/output.js @@ -34,12 +34,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -49,9 +43,31 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -66,10 +82,12 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "bar", value: function() { @@ -85,10 +103,12 @@ var _typeof = function(obj) { ]), B; }(A), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), _createClass(C, [ + return _createClass(C, [ { key: "foo", value: function() { @@ -129,8 +149,10 @@ var _typeof = function(obj) { ]), AA; }(), BB = function(AA) { "use strict"; + _inherits(BB, AA); + var _super = _createSuper(BB); function BB() { - return _classCallCheck(this, BB), _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _classCallCheck(this, BB), _super.apply(this, arguments); } - return _inherits(BB, AA), BB; + return BB; }(AA); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.1.normal/output.js index 4db214a1fd1..a21bad2b6b4 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -65,9 +90,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -82,9 +108,10 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.2.minified/output.js index e2d55343c21..9eb16a9c549 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1/input.ts/es5.2.minified/output.js @@ -22,29 +22,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; - var Constructor, protoProps, staticProps; + _inherits(B, A); + var Constructor, protoProps, staticProps, _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), protoProps = [ + return protoProps = [ { key: "foo", value: function() { @@ -54,9 +71,11 @@ var _typeof = function(obj) { ], _defineProperties((Constructor = B).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), B; }(A1), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), C; + return C; }(A1), a = new B; a.foo(), (a = new C).foo(); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.1.normal/output.js index 556df7c6d34..f9090c16db3 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.1.normal/output.js @@ -102,93 +102,128 @@ function _wrapNativeSuper(Class) { }; return _wrapNativeSuper(Class); } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = /*#__PURE__*/ function(Object) { "use strict"; _inherits(C1, Object); + var _super = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super.apply(this, arguments); } return C1; }(_wrapNativeSuper(Object)); var C2 = /*#__PURE__*/ function(Function) { "use strict"; _inherits(C2, Function); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(_wrapNativeSuper(Function)); var C3 = /*#__PURE__*/ function(String) { "use strict"; _inherits(C3, String); + var _super = _createSuper(C3); function C3() { _classCallCheck(this, C3); - return _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _super.apply(this, arguments); } return C3; }(_wrapNativeSuper(String)); var C4 = /*#__PURE__*/ function(Boolean) { "use strict"; _inherits(C4, Boolean); + var _super = _createSuper(C4); function C4() { _classCallCheck(this, C4); - return _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _super.apply(this, arguments); } return C4; }(_wrapNativeSuper(Boolean)); var C5 = /*#__PURE__*/ function(Number) { "use strict"; _inherits(C5, Number); + var _super = _createSuper(C5); function C5() { _classCallCheck(this, C5); - return _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _super.apply(this, arguments); } return C5; }(_wrapNativeSuper(Number)); var C6 = /*#__PURE__*/ function(Date) { "use strict"; _inherits(C6, Date); + var _super = _createSuper(C6); function C6() { _classCallCheck(this, C6); - return _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _super.apply(this, arguments); } return C6; }(_wrapNativeSuper(Date)); var C7 = /*#__PURE__*/ function(RegExp) { "use strict"; _inherits(C7, RegExp); + var _super = _createSuper(C7); function C7() { _classCallCheck(this, C7); - return _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _super.apply(this, arguments); } return C7; }(_wrapNativeSuper(RegExp)); var C8 = /*#__PURE__*/ function(Error) { "use strict"; _inherits(C8, Error); + var _super = _createSuper(C8); function C8() { _classCallCheck(this, C8); - return _possibleConstructorReturn(this, _getPrototypeOf(C8).apply(this, arguments)); + return _super.apply(this, arguments); } return C8; }(_wrapNativeSuper(Error)); var C9 = /*#__PURE__*/ function(Array) { "use strict"; _inherits(C9, Array); + var _super = _createSuper(C9); function C9() { _classCallCheck(this, C9); - return _possibleConstructorReturn(this, _getPrototypeOf(C9).apply(this, arguments)); + return _super.apply(this, arguments); } return C9; }(_wrapNativeSuper(Array)); var C10 = /*#__PURE__*/ function(Array) { "use strict"; _inherits(C10, Array); + var _super = _createSuper(C10); function C10() { _classCallCheck(this, C10); - return _possibleConstructorReturn(this, _getPrototypeOf(C10).apply(this, arguments)); + return _super.apply(this, arguments); } return C10; }(_wrapNativeSuper(Array)); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.2.minified/output.js index 1c38da5f730..8bbe8b5e830 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingBuiltinType/input.ts/es5.2.minified/output.js @@ -36,20 +36,11 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; function _wrapNativeSuper(Class) { var _cache = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(Class) { @@ -73,64 +64,108 @@ function _wrapNativeSuper(Class) { }), _setPrototypeOf(Wrapper, Class); }, _wrapNativeSuper(Class); } +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} var C1 = function(Object) { "use strict"; + _inherits(C1, Object); + var _super = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super.apply(this, arguments); } - return _inherits(C1, Object), C1; + return C1; }(_wrapNativeSuper(Object)), C2 = function(Function) { "use strict"; + _inherits(C2, Function); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, Function), C2; + return C2; }(_wrapNativeSuper(Function)), C3 = function(String) { "use strict"; + _inherits(C3, String); + var _super = _createSuper(C3); function C3() { - return _classCallCheck(this, C3), _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _classCallCheck(this, C3), _super.apply(this, arguments); } - return _inherits(C3, String), C3; + return C3; }(_wrapNativeSuper(String)), C4 = function(Boolean) { "use strict"; + _inherits(C4, Boolean); + var _super = _createSuper(C4); function C4() { - return _classCallCheck(this, C4), _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _classCallCheck(this, C4), _super.apply(this, arguments); } - return _inherits(C4, Boolean), C4; + return C4; }(_wrapNativeSuper(Boolean)), C5 = function(Number) { "use strict"; + _inherits(C5, Number); + var _super = _createSuper(C5); function C5() { - return _classCallCheck(this, C5), _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _classCallCheck(this, C5), _super.apply(this, arguments); } - return _inherits(C5, Number), C5; + return C5; }(_wrapNativeSuper(Number)), C6 = function(Date) { "use strict"; + _inherits(C6, Date); + var _super = _createSuper(C6); function C6() { - return _classCallCheck(this, C6), _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _classCallCheck(this, C6), _super.apply(this, arguments); } - return _inherits(C6, Date), C6; + return C6; }(_wrapNativeSuper(Date)), C7 = function(RegExp) { "use strict"; + _inherits(C7, RegExp); + var _super = _createSuper(C7); function C7() { - return _classCallCheck(this, C7), _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _classCallCheck(this, C7), _super.apply(this, arguments); } - return _inherits(C7, RegExp), C7; + return C7; }(_wrapNativeSuper(RegExp)), C8 = function(Error) { "use strict"; + _inherits(C8, Error); + var _super = _createSuper(C8); function C8() { - return _classCallCheck(this, C8), _possibleConstructorReturn(this, _getPrototypeOf(C8).apply(this, arguments)); + return _classCallCheck(this, C8), _super.apply(this, arguments); } - return _inherits(C8, Error), C8; + return C8; }(_wrapNativeSuper(Error)), C9 = function(Array) { "use strict"; + _inherits(C9, Array); + var _super = _createSuper(C9); function C9() { - return _classCallCheck(this, C9), _possibleConstructorReturn(this, _getPrototypeOf(C9).apply(this, arguments)); + return _classCallCheck(this, C9), _super.apply(this, arguments); } - return _inherits(C9, Array), C9; + return C9; }(_wrapNativeSuper(Array)), C10 = function(Array) { "use strict"; + _inherits(C10, Array); + var _super = _createSuper(C10); function C10() { - return _classCallCheck(this, C10), _possibleConstructorReturn(this, _getPrototypeOf(C10).apply(this, arguments)); + return _classCallCheck(this, C10), _super.apply(this, arguments); } - return _inherits(C10, Array), C10; + return C10; }(_wrapNativeSuper(Array)); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.1.normal/output.js index 4ad3f8292b3..81751cbf9b5 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.1.normal/output.js @@ -44,23 +44,50 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var D0 = // Error, no Base constructor function /*#__PURE__*/ function(Base) { "use strict"; _inherits(D0, Base); + var _super = _createSuper(D0); function D0() { _classCallCheck(this, D0); - return _possibleConstructorReturn(this, _getPrototypeOf(D0).apply(this, arguments)); + return _super.apply(this, arguments); } return D0; }(Base); var D1 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D1, _super); + var _super1 = _createSuper(D1); function D1() { _classCallCheck(this, D1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D1).call(this, "abc", "def")); + _this = _super1.call(this, "abc", "def"); _this.x = "x"; _this.y = "y"; return _this; @@ -70,11 +97,12 @@ var D1 = /*#__PURE__*/ function(_super) { var D2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D2, _super); + var _super2 = _createSuper(D2); function D2() { _classCallCheck(this, D2); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).call(this, 10)); - _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).call(this, 10, 20)); + _this = _super2.call(this, 10); + _this = _super2.call(this, 10, 20); _this.x = 1; _this.y = 2; return _this; @@ -84,10 +112,11 @@ var D2 = /*#__PURE__*/ function(_super) { var D3 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D3, _super); + var _super3 = _createSuper(D3); function D3() { _classCallCheck(this, D3); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D3).call(this, "abc", 42)); + _this = _super3.call(this, "abc", 42); _this.x = "x"; _this.y = 2; return _this; @@ -98,9 +127,10 @@ var D4 = // Error, no constructors with three type arguments /*#__PURE__*/ function(_super) { "use strict"; _inherits(D4, _super); + var _super4 = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super4.apply(this, arguments); } return D4; }(getBase()); @@ -108,9 +138,10 @@ var D5 = // Error, constructor return types differ /*#__PURE__*/ function(_super) { "use strict"; _inherits(D5, _super); + var _super5 = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super5.apply(this, arguments); } return D5; }(getBadBase()); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.2.minified/output.js index ad3f410746d..f94a5d2e747 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingClassLikeType/input.ts/es5.2.minified/output.js @@ -16,56 +16,84 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, D0 = function(Base) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var D0 = function(Base) { "use strict"; + _inherits(D0, Base); + var _super = _createSuper(D0); function D0() { - return _classCallCheck(this, D0), _possibleConstructorReturn(this, _getPrototypeOf(D0).apply(this, arguments)); + return _classCallCheck(this, D0), _super.apply(this, arguments); } - return _inherits(D0, Base), D0; + return D0; }(Base), D1 = function(_super) { "use strict"; + _inherits(D1, _super); + var _super1 = _createSuper(D1); function D1() { var _this; - return _classCallCheck(this, D1), (_this = _possibleConstructorReturn(this, _getPrototypeOf(D1).call(this, "abc", "def"))).x = "x", _this.y = "y", _this; + return _classCallCheck(this, D1), (_this = _super1.call(this, "abc", "def")).x = "x", _this.y = "y", _this; } - return _inherits(D1, _super), D1; + return D1; }(getBase()), D2 = function(_super) { "use strict"; + _inherits(D2, _super); + var _super2 = _createSuper(D2); function D2() { var _this; - return _classCallCheck(this, D2), _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).call(this, 10)), _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).call(this, 10, 20)), _this.x = 1, _this.y = 2, _this; + return _classCallCheck(this, D2), _this = _super2.call(this, 10), _this = _super2.call(this, 10, 20), _this.x = 1, _this.y = 2, _this; } - return _inherits(D2, _super), D2; + return D2; }(getBase()), D3 = function(_super) { "use strict"; + _inherits(D3, _super); + var _super3 = _createSuper(D3); function D3() { var _this; - return _classCallCheck(this, D3), (_this = _possibleConstructorReturn(this, _getPrototypeOf(D3).call(this, "abc", 42))).x = "x", _this.y = 2, _this; + return _classCallCheck(this, D3), (_this = _super3.call(this, "abc", 42)).x = "x", _this.y = 2, _this; } - return _inherits(D3, _super), D3; + return D3; }(getBase()), D4 = function(_super) { "use strict"; + _inherits(D4, _super); + var _super4 = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super4.apply(this, arguments); } - return _inherits(D4, _super), D4; + return D4; }(getBase()), D5 = function(_super) { "use strict"; + _inherits(D5, _super); + var _super5 = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super5.apply(this, arguments); } - return _inherits(D5, _super), D5; + return D5; }(getBadBase()); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.1.normal/output.js index f46c70f6dd9..88cbe1bfd49 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var x1; function foo1() { this.x = 1; @@ -51,63 +76,70 @@ function foo1() { var C1 = /*#__PURE__*/ function(undefined) { "use strict"; _inherits(C1, undefined); + var _super = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super.apply(this, arguments); } return C1; }(undefined); var C2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C2, _super); + var _super1 = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super1.apply(this, arguments); } return C2; }(true); var C3 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C3, _super); + var _super2 = _createSuper(C3); function C3() { _classCallCheck(this, C3); - return _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _super2.apply(this, arguments); } return C3; }(false); var C4 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C4, _super); + var _super3 = _createSuper(C4); function C4() { _classCallCheck(this, C4); - return _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _super3.apply(this, arguments); } return C4; }(42); var C5 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C5, _super); + var _super4 = _createSuper(C5); function C5() { _classCallCheck(this, C5); - return _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _super4.apply(this, arguments); } return C5; }("hello"); var C6 = /*#__PURE__*/ function(x) { "use strict"; _inherits(C6, x); + var _super = _createSuper(C6); function C6() { _classCallCheck(this, C6); - return _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _super.apply(this, arguments); } return C6; }(x1); var C7 = /*#__PURE__*/ function(foo) { "use strict"; _inherits(C7, foo); + var _super = _createSuper(C7); function C7() { _classCallCheck(this, C7); - return _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _super.apply(this, arguments); } return C7; }(foo1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.2.minified/output.js index 4a111dc3432..063a753f0bc 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNonConstructor/input.ts/es5.2.minified/output.js @@ -16,61 +16,91 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function(undefined) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x1, C1 = function(undefined) { "use strict"; + _inherits(C1, undefined); + var _super = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super.apply(this, arguments); } - return _inherits(C1, undefined), C1; + return C1; }(void 0), C2 = function(_super) { "use strict"; + _inherits(C2, _super); + var _super1 = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super1.apply(this, arguments); } - return _inherits(C2, _super), C2; + return C2; }(!0), C3 = function(_super) { "use strict"; + _inherits(C3, _super); + var _super2 = _createSuper(C3); function C3() { - return _classCallCheck(this, C3), _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _classCallCheck(this, C3), _super2.apply(this, arguments); } - return _inherits(C3, _super), C3; + return C3; }(!1), C4 = function(_super) { "use strict"; + _inherits(C4, 42); + var _super3 = _createSuper(C4); function C4() { - return _classCallCheck(this, C4), _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _classCallCheck(this, C4), _super3.apply(this, arguments); } - return _inherits(C4, 42), C4; + return C4; }(42), C5 = function(_super) { "use strict"; + _inherits(C5, "hello"); + var _super4 = _createSuper(C5); function C5() { - return _classCallCheck(this, C5), _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _classCallCheck(this, C5), _super4.apply(this, arguments); } - return _inherits(C5, "hello"), C5; + return C5; }("hello"), C6 = function(x) { "use strict"; + _inherits(C6, x); + var _super = _createSuper(C6); function C6() { - return _classCallCheck(this, C6), _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _classCallCheck(this, C6), _super.apply(this, arguments); } - return _inherits(C6, x), C6; + return C6; }(x1), C7 = function(foo) { "use strict"; + _inherits(C7, foo); + var _super = _createSuper(C7); function C7() { - return _classCallCheck(this, C7), _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _classCallCheck(this, C7), _super.apply(this, arguments); } - return _inherits(C7, foo), C7; + return C7; }(function() { this.x = 1; }); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.1.normal/output.js index c42a560f821..354aa198ae0 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.1.normal/output.js @@ -44,31 +44,59 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C1, _super); + var _super1 = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super1.apply(this, arguments); } return C1; }(null); var C2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C2, _super); + var _super2 = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super2.apply(this, arguments); } return C2; }(null); var C3 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C3, _super); + var _super3 = _createSuper(C3); function C3() { _classCallCheck(this, C3); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + _this = _super3.apply(this, arguments); _this.x = 1; return _this; } @@ -77,10 +105,11 @@ var C3 = /*#__PURE__*/ function(_super) { var C4 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C4, _super); + var _super4 = _createSuper(C4); function C4() { _classCallCheck(this, C4); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + _this = _super4.apply(this, arguments); _this.x = 1; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.2.minified/output.js index 6f3f096fe0a..d2c2e255ab4 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classExtendingNull/input.ts/es5.2.minified/output.js @@ -16,43 +16,67 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function(_super) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C1 = function(_super) { "use strict"; + _inherits(C1, null); + var _super1 = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super1.apply(this, arguments); } - return _inherits(C1, null), C1; + return C1; }(null), C2 = function(_super) { "use strict"; + _inherits(C2, null); + var _super2 = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super2.apply(this, arguments); } - return _inherits(C2, null), C2; + return C2; }(null), C3 = function(_super) { "use strict"; + _inherits(C3, null); + var _super3 = _createSuper(C3); function C3() { var _this; - return _classCallCheck(this, C3), _this = _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)), _this.x = 1, _this; + return _classCallCheck(this, C3), _this = _super3.apply(this, arguments), _this.x = 1, _this; } - return _inherits(C3, null), C3; + return C3; }(null), C4 = function(_super) { "use strict"; + _inherits(C4, null); + var _super4 = _createSuper(C4); function C4() { var _this; - return _classCallCheck(this, C4), _this = _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)), _this.x = 1, _this; + return _classCallCheck(this, C4), _this = _super4.apply(this, arguments), _this.x = 1, _this; } - return _inherits(C4, null), C4; + return C4; }(null); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.1.normal/output.js index 07bd7f84f4f..7ecea53ba74 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C() { @@ -81,9 +106,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -115,9 +141,10 @@ var C2 = /*#__PURE__*/ function() { var D2 = /*#__PURE__*/ function(C2) { "use strict"; _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(C2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.2.minified/output.js index f036d2f84b7..d572ca18d28 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendingClass/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var d, d2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var d, d2, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -58,10 +74,12 @@ var d, d2, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C); d.foo, d.bar, d.thing(), D.other(); var C2 = function() { @@ -84,9 +102,11 @@ var C2 = function() { ]), C2; }(), D2 = function(C2) { "use strict"; + _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, C2), D2; + return D2; }(C2); d2.foo, d2.bar, d2.thing(""), D2.other(1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.1.normal/output.js index bfee3e20e41..8f0ba5f7b5a 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = /*#__PURE__*/ function(C) { "use strict"; _inherits(C1, C); + var _super = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super.apply(this, arguments); } return C1; } // error @@ -57,9 +83,10 @@ var C1 = /*#__PURE__*/ function(C) { var D1 = /*#__PURE__*/ function(D) { "use strict"; _inherits(D1, D); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; } // error @@ -67,9 +94,10 @@ var D1 = /*#__PURE__*/ function(D) { var E1 = /*#__PURE__*/ function(E) { "use strict"; _inherits(E1, E); + var _super = _createSuper(E1); function E1() { _classCallCheck(this, E1); - return _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _super.apply(this, arguments); } return E1; } // error diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.2.minified/output.js index 5d2f644f11f..1037df8601b 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItself/input.ts/es5.2.minified/output.js @@ -16,36 +16,58 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function(C) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C1 = function(C) { "use strict"; + _inherits(C1, C); + var _super = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super.apply(this, arguments); } - return _inherits(C1, C), C1; + return C1; }(C1), D1 = function(D) { "use strict"; + _inherits(D1, D); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, D), D1; + return D1; }(D1), E1 = function(E) { "use strict"; + _inherits(E1, E); + var _super = _createSuper(E1); function E1() { - return _classCallCheck(this, E1), _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _classCallCheck(this, E1), _super.apply(this, arguments); } - return _inherits(E1, E), E1; + return E1; } // error (E1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.1.normal/output.js index fecf3502029..d20e7680502 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(E) { "use strict"; _inherits(C, E); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; } // error @@ -57,27 +83,30 @@ var C = /*#__PURE__*/ function(E) { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); var E1 = /*#__PURE__*/ function(D) { "use strict"; _inherits(E1, D); + var _super = _createSuper(E1); function E1() { _classCallCheck(this, E1); - return _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _super.apply(this, arguments); } return E1; }(D); var C2 = /*#__PURE__*/ function(E2) { "use strict"; _inherits(C2, E2); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; } // error @@ -85,18 +114,20 @@ var C2 = /*#__PURE__*/ function(E2) { var D2 = /*#__PURE__*/ function(C2) { "use strict"; _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(C2); var E21 = /*#__PURE__*/ function(D2) { "use strict"; _inherits(E21, D2); + var _super = _createSuper(E21); function E21() { _classCallCheck(this, E21); - return _possibleConstructorReturn(this, _getPrototypeOf(E21).apply(this, arguments)); + return _super.apply(this, arguments); } return E21; }(D2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.2.minified/output.js index 996d2628d6e..8419df55d01 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly/input.ts/es5.2.minified/output.js @@ -16,53 +16,81 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function(E) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function(E) { "use strict"; + _inherits(C, E); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, E), C; + return C; }(E1), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C), E1 = function(D) { "use strict"; + _inherits(E1, D); + var _super = _createSuper(E1); function E1() { - return _classCallCheck(this, E1), _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _classCallCheck(this, E1), _super.apply(this, arguments); } - return _inherits(E1, D), E1; + return E1; }(D), C2 = function(E2) { "use strict"; + _inherits(C2, E2); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, E2), C2; + return C2; }(E21), D2 = function(C2) { "use strict"; + _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, C2), D2; + return D2; }(C2), E21 = function(D2) { "use strict"; + _inherits(E21, D2); + var _super = _createSuper(E21); function E21() { - return _classCallCheck(this, E21), _possibleConstructorReturn(this, _getPrototypeOf(E21).apply(this, arguments)); + return _classCallCheck(this, E21), _super.apply(this, arguments); } - return _inherits(E21, D2), E21; + return E21; }(D2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.1.normal/output.js index 7fcb56ab52f..e13b064d600 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(_E) { "use strict"; _inherits(C, _E); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; } // error @@ -59,9 +85,10 @@ var M1; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -73,9 +100,10 @@ var N1; var E = /*#__PURE__*/ function(_D) { "use strict"; _inherits(E, _D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } return E; }(M1.D); @@ -87,9 +115,10 @@ var O; var C2 = /*#__PURE__*/ function(_E2) { "use strict"; _inherits(C2, _E2); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; } // error @@ -99,9 +128,10 @@ var O; var D2 = /*#__PURE__*/ function(C2) { "use strict"; _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(C2); @@ -113,9 +143,10 @@ var O; var E2 = /*#__PURE__*/ function(_D2) { "use strict"; _inherits(E2, _D2); + var _super = _createSuper(E2); function E2() { _classCallCheck(this, E2); - return _possibleConstructorReturn(this, _getPrototypeOf(E2).apply(this, arguments)); + return _super.apply(this, arguments); } return E2; }(P1.D2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.2.minified/output.js index 3d37f087bff..8fece8bb2bb 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly2/input.ts/es5.2.minified/output.js @@ -16,71 +16,99 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var M1, N1, O, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function(_E) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var M1, N1, O, C = function(_E) { "use strict"; + _inherits(C, _E); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, _E), C; + return C; }(N1.E); !function(M) { var D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C); M.D = D; }(M1 || (M1 = { })), (function(N) { var E = function(_D) { "use strict"; + _inherits(E, _D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, _D), E; + return E; }(M1.D); N.E = E; })(N1 || (N1 = { })), (function(O) { var P1, Q1, C2 = function(_E2) { "use strict"; + _inherits(C2, _E2); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, _E2), C2; + return C2; }(Q1.E2); (function(P) { var D2 = function(C2) { "use strict"; + _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, C2), D2; + return D2; }(C2); P.D2 = D2; })(P1 || (P1 = { })), (function(Q) { var E2 = function(_D2) { "use strict"; + _inherits(E2, _D2); + var _super = _createSuper(E2); function E2() { - return _classCallCheck(this, E2), _possibleConstructorReturn(this, _getPrototypeOf(E2).apply(this, arguments)); + return _classCallCheck(this, E2), _super.apply(this, arguments); } - return _inherits(E2, _D2), E2; + return E2; }(P1.D2); Q.E2 = E2; })(Q1 || (Q1 = { diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.1.normal/output.js index 533c30b3ff3..426279c2898 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.1.normal/output.js @@ -44,13 +44,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // @Filename: classExtendsItselfIndirectly_file1.ts /*#__PURE__*/ function(E) { "use strict"; _inherits(C, E); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; } // error @@ -59,9 +85,10 @@ var D = // @Filename: classExtendsItselfIndirectly_file2.ts /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -69,9 +96,10 @@ var E1 = // @Filename: classExtendsItselfIndirectly_file3.ts /*#__PURE__*/ function(D) { "use strict"; _inherits(E1, D); + var _super = _createSuper(E1); function E1() { _classCallCheck(this, E1); - return _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _super.apply(this, arguments); } return E1; }(D); @@ -79,9 +107,10 @@ var C2 = // @Filename: classExtendsItselfIndirectly_file4.ts /*#__PURE__*/ function(E2) { "use strict"; _inherits(C2, E2); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; } // error @@ -90,9 +119,10 @@ var D2 = // @Filename: classExtendsItselfIndirectly_file5.ts /*#__PURE__*/ function(C2) { "use strict"; _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(C2); @@ -100,9 +130,10 @@ var E21 = // @Filename: classExtendsItselfIndirectly_file6.ts /*#__PURE__*/ function(D2) { "use strict"; _inherits(E21, D2); + var _super = _createSuper(E21); function E21() { _classCallCheck(this, E21); - return _possibleConstructorReturn(this, _getPrototypeOf(E21).apply(this, arguments)); + return _super.apply(this, arguments); } return E21; }(D2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.2.minified/output.js index 996d2628d6e..8419df55d01 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly3/input.ts/es5.2.minified/output.js @@ -16,53 +16,81 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function(E) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function(E) { "use strict"; + _inherits(C, E); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, E), C; + return C; }(E1), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C), E1 = function(D) { "use strict"; + _inherits(E1, D); + var _super = _createSuper(E1); function E1() { - return _classCallCheck(this, E1), _possibleConstructorReturn(this, _getPrototypeOf(E1).apply(this, arguments)); + return _classCallCheck(this, E1), _super.apply(this, arguments); } - return _inherits(E1, D), E1; + return E1; }(D), C2 = function(E2) { "use strict"; + _inherits(C2, E2); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, E2), C2; + return C2; }(E21), D2 = function(C2) { "use strict"; + _inherits(D2, C2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, C2), D2; + return D2; }(C2), E21 = function(D2) { "use strict"; + _inherits(E21, D2); + var _super = _createSuper(E21); function E21() { - return _classCallCheck(this, E21), _possibleConstructorReturn(this, _getPrototypeOf(E21).apply(this, arguments)); + return _classCallCheck(this, E21), _super.apply(this, arguments); } - return _inherits(E21, D2), E21; + return E21; }(D2); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.1.normal/output.js index 6191106ca22..9ea65b6d7fe 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -54,9 +79,10 @@ var M; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.2.minified/output.js index 475de8f169f..8e9c477183e 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsShadowedConstructorFunction/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ var M, C = function() { !function(M) { var D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,7 +27,35 @@ var M, C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, 1), D; + }(D, 1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(1); }(M || (M = { })); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.1.normal/output.js index 9b477bbfed7..2af43007338 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.1.normal/output.js @@ -44,15 +44,41 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function foo1() { } var x = new foo1(); // can be used as a constructor function var C = /*#__PURE__*/ function(foo) { "use strict"; _inherits(C, foo); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; } // error, cannot extend it though diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.2.minified/output.js index 1c9279408d0..f924e9e494b 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classExtendsValidConstructorFunction/input.ts/es5.2.minified/output.js @@ -13,16 +13,7 @@ function foo1() { new foo1(); var C = function(foo) { "use strict"; - function C() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -31,6 +22,36 @@ var C = function(foo) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, foo), C; + }(C, foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, C), _super.apply(this, arguments); + } + return C; } // error, cannot extend it though (foo1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.1.normal/output.js index d4bc3e54485..a3760ba6b90 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.2.minified/output.js index 8caeee4a6c4..2b9233bd7c9 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.1.normal/output.js index d4bc3e54485..a3760ba6b90 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.2.minified/output.js index 8caeee4a6c4..2b9233bd7c9 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.1.normal/output.js index 9f93778b0ed..68c97ac8ca5 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(x) { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, x)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(x) { + _classCallCheck(this, Derived1); + return _super.call(this, x); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2(x) { _classCallCheck(this, Derived2); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived2).call(this, x)); + var _this = _super.call(this, x); return _possibleConstructorReturn(_this, 1); } return Derived2; diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.2.minified/output.js index 32661b3c0ba..bac1baf7781 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/constructorFunctionTypeIsAssignableToBaseType2/input.ts/es5.2.minified/output.js @@ -29,21 +29,45 @@ function _setPrototypeOf(o, p) { } var _typeof = function(obj) { return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(x) { +}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return _possibleConstructorReturn(this, result); + }; +} +var Base1 = function(x) { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived(x) { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, x)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(x) { + return _classCallCheck(this, Derived1), _super.call(this, x); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2(x) { - _classCallCheck(this, Derived2); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived2).call(this, x)); - return _possibleConstructorReturn(_this, 1); + return _classCallCheck(this, Derived2), _possibleConstructorReturn(_super.call(this, x), 1); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.1.normal/output.js index 73effe9d2cf..f76dba77f24 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.1.normal/output.js @@ -44,20 +44,46 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = function Derived() { +var Derived1 = function Derived1() { "use strict"; - _classCallCheck(this, Derived); + _classCallCheck(this, Derived1); }; var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.2.minified/output.js index ffdcd0abce0..272e38ab0f8 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/classHeritageSpecification/derivedTypeDoesNotRequireExtendsClause/input.ts/es5.2.minified/output.js @@ -14,19 +14,12 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function() { +}, Derived1 = function() { "use strict"; - _classCallCheck(this, Derived); + _classCallCheck(this, Derived1); }, Derived2 = function(Base) { "use strict"; - function Derived2() { - var self, call, obj; - return _classCallCheck(this, Derived2), self = this, call = _getPrototypeOf(Derived2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,5 +28,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived2, Base), Derived2; + }(Derived2, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived2); + function Derived2() { + return _classCallCheck(this, Derived2), _super.apply(this, arguments); + } + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.1.normal/output.js index 070c1b686f0..ed9038c22be 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var BaseClass = /*#__PURE__*/ function() { "use strict"; function BaseClass() { @@ -75,9 +100,10 @@ var BaseClass = /*#__PURE__*/ function() { var Child = /*#__PURE__*/ function(BaseClass) { "use strict"; _inherits(Child, BaseClass); + var _super = _createSuper(Child); function Child() { _classCallCheck(this, Child); - return _possibleConstructorReturn(this, _getPrototypeOf(Child).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Child, [ { @@ -105,9 +131,10 @@ var ChildNoBaseClass = /*#__PURE__*/ function() { var Grandchild = /*#__PURE__*/ function(ChildNoBaseClass) { "use strict"; _inherits(Grandchild, ChildNoBaseClass); + var _super = _createSuper(Grandchild); function Grandchild() { _classCallCheck(this, Grandchild); - return _possibleConstructorReturn(this, _getPrototypeOf(Grandchild).apply(this, arguments)); + return _super.apply(this, arguments); } return Grandchild; }(ChildNoBaseClass); diff --git a/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.2.minified/output.js index 5f610a7b144..8adbbbd4bc6 100644 --- a/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classDeclarations/mergedInheritedClassInterface/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var child, grandchild, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, BaseClass = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var child, grandchild, BaseClass = function() { "use strict"; function BaseClass() { _classCallCheck(this, BaseClass); @@ -52,10 +68,12 @@ var child, grandchild, _typeof = function(obj) { ]), BaseClass; }(), Child = function(BaseClass) { "use strict"; + _inherits(Child, BaseClass); + var _super = _createSuper(Child); function Child() { - return _classCallCheck(this, Child), _possibleConstructorReturn(this, _getPrototypeOf(Child).apply(this, arguments)); + return _classCallCheck(this, Child), _super.apply(this, arguments); } - return _inherits(Child, BaseClass), _createClass(Child, [ + return _createClass(Child, [ { key: "method", value: function() { @@ -76,9 +94,11 @@ var child, grandchild, _typeof = function(obj) { ]), ChildNoBaseClass; }(), Grandchild = function(ChildNoBaseClass) { "use strict"; + _inherits(Grandchild, ChildNoBaseClass); + var _super = _createSuper(Grandchild); function Grandchild() { - return _classCallCheck(this, Grandchild), _possibleConstructorReturn(this, _getPrototypeOf(Grandchild).apply(this, arguments)); + return _classCallCheck(this, Grandchild), _super.apply(this, arguments); } - return _inherits(Grandchild, ChildNoBaseClass), Grandchild; + return Grandchild; }(ChildNoBaseClass); child.required, child.optional, child.additional, child.baseNumber, child.classNumber, child.baseMethod(), child.method(), grandchild.required, grandchild.optional, grandchild.additional2, grandchild.classString, grandchild.method2(); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.1.normal/output.js index c97e622dab9..07b59b099af 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var D = function D() { "use strict"; _classCallCheck(this, D); @@ -51,9 +76,10 @@ var D = function D() { var v = /*#__PURE__*/ function(D) { "use strict"; _inherits(C, D); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(D); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.2.minified/output.js index 836ae927e84..7b8fae4cc3d 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression2/input.ts/es5.2.minified/output.js @@ -17,13 +17,6 @@ var D1 = function() { }; !function(D) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { @@ -34,4 +27,31 @@ var D1 = function() { } }), superClass && _setPrototypeOf(subClass, superClass); }(C, D); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } }(D1); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.1.normal/output.js index d7928b5b4ee..10d6ac4af89 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.1.normal/output.js @@ -44,13 +44,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(_super) { "use strict"; _inherits(_class, _super); + var _super1 = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super1.apply(this, arguments); _this.c = 3; return _this; } @@ -58,10 +84,11 @@ var C = /*#__PURE__*/ function(_super) { }(/*#__PURE__*/ function(_super) { "use strict"; _inherits(_class, _super); + var _super2 = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super2.apply(this, arguments); _this.b = 2; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.2.minified/output.js index c494fbe100c..e8588f14e6b 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classExpression3/input.ts/es5.2.minified/output.js @@ -16,33 +16,53 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, c = new (function(_super) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var c = new (function(_super) { "use strict"; + _inherits(_class, _super); + var _super1 = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.c = 3, _this; + return _classCallCheck(this, _class), _this = _super1.apply(this, arguments), _this.c = 3, _this; } - return _inherits(_class, _super), _class; + return _class; }(function(_super) { "use strict"; + _inherits(_class, _super); + var _super2 = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.b = 2, _this; + return _classCallCheck(this, _class), _this = _super2.apply(this, arguments), _this.b = 2, _this; } - return _inherits(_class, _super), _class; + return _class; }(function _class() { "use strict"; _classCallCheck(this, _class), this.a = 1; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.1.normal/output.js index 21b0321e11f..ad2050f10b7 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _class, _class1; var C = function C() { "use strict"; @@ -53,9 +78,10 @@ var C = function C() { var tmp = param[/*#__PURE__*/ (_class = function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class.x = 1, _class).x], b = tmp === void 0 ? "" : tmp; @@ -66,9 +92,10 @@ var x = ""; var tmp = param[/*#__PURE__*/ (_class1 = function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = param1 === void 0 ? x : param1; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.2.minified/output.js index 20ef0b75d8c..5191d851ffd 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.2/input.ts/es5.2.minified/output.js @@ -16,37 +16,57 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _class, _class1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _class, _class1, C = function() { "use strict"; _classCallCheck(this, C); }; !function(param) { (void 0)[((_class = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C)).x = 1, _class).x]; }(), (function(param, param1) { (void 0)[((_class1 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C)).x = 1, _class1).x]; })(); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.1.normal/output.js index 21b0321e11f..ad2050f10b7 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _class, _class1; var C = function C() { "use strict"; @@ -53,9 +78,10 @@ var C = function C() { var tmp = param[/*#__PURE__*/ (_class = function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class.x = 1, _class).x], b = tmp === void 0 ? "" : tmp; @@ -66,9 +92,10 @@ var x = ""; var tmp = param[/*#__PURE__*/ (_class1 = function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = param1 === void 0 ? x : param1; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.2.minified/output.js index 20ef0b75d8c..5191d851ffd 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterBindingPattern.3/input.ts/es5.2.minified/output.js @@ -16,37 +16,57 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _class, _class1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _class, _class1, C = function() { "use strict"; _classCallCheck(this, C); }; !function(param) { (void 0)[((_class = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C)).x = 1, _class).x]; }(), (function(param, param1) { (void 0)[((_class1 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C)).x = 1, _class1).x]; })(); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.1.normal/output.js index 38c2d04fb04..72926a964b0 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _class2, _class1; var C = function C() { "use strict"; @@ -53,9 +78,10 @@ var C = function C() { var b = param === void 0 ? (_class2 = /*#__PURE__*/ function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class2.x = 1, _class2) : param; @@ -66,9 +92,10 @@ var x = ""; var b = param === void 0 ? (_class1 = /*#__PURE__*/ function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class1.x = 1, _class1) : param, d = param1 === void 0 ? x : param1; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.2.minified/output.js index 7b3de683c0e..dea616a84e1 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.2/input.ts/es5.2.minified/output.js @@ -16,37 +16,57 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _class2, _class1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _class2, _class1, C1 = function() { "use strict"; _classCallCheck(this, C1); }; !function(param) { (_class2 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C1)).x = 1; }(), (function(param, param1) { (_class1 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C1)).x = 1; })(); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.1.normal/output.js index 38c2d04fb04..72926a964b0 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _class2, _class1; var C = function C() { "use strict"; @@ -53,9 +78,10 @@ var C = function C() { var b = param === void 0 ? (_class2 = /*#__PURE__*/ function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class2.x = 1, _class2) : param; @@ -66,9 +92,10 @@ var x = ""; var b = param === void 0 ? (_class1 = /*#__PURE__*/ function(C) { "use strict"; _inherits(_class, C); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; }(C), _class1.x = 1, _class1) : param, d = param1 === void 0 ? x : param1; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.2.minified/output.js index 7b3de683c0e..dea616a84e1 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/classWithStaticFieldInParameterInitializer.3/input.ts/es5.2.minified/output.js @@ -16,37 +16,57 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _class2, _class1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _class2, _class1, C1 = function() { "use strict"; _classCallCheck(this, C1); }; !function(param) { (_class2 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C1)).x = 1; }(), (function(param, param1) { (_class1 = (function(C) { "use strict"; + _inherits(_class, C); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, C), _class; + return _class; })(C1)).x = 1; })(); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.1.normal/output.js index 58b584e8813..43958f598b6 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var x1 = function x1() { "use strict"; _classCallCheck(this, x1); @@ -55,9 +80,10 @@ var x1 = foo1; var y = /*#__PURE__*/ function(x) { "use strict"; _inherits(y, x); + var _super = _createSuper(y); function y() { _classCallCheck(this, y); - return _possibleConstructorReturn(this, _getPrototypeOf(y).apply(this, arguments)); + return _super.apply(this, arguments); } return y; }(x1); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.2.minified/output.js index c799ce3f5db..ef45f87b494 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/extendClassExpressionFromModule/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ var x1 = function() { module.exports = x1; var x1 = require("./foo1"), y = function(x) { "use strict"; - function y() { - var self, call, obj; - return _classCallCheck(this, y), self = this, call = _getPrototypeOf(y).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,6 +27,34 @@ var x1 = require("./foo1"), y = function(x) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(y, x), y; + }(y, x); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(y); + function y() { + return _classCallCheck(this, y), _super.apply(this, arguments); + } + return y; }(x1); export { }; diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.1.normal/output.js index b0f7af82f0b..028465d507b 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -53,9 +78,10 @@ function B1() { return /*#__PURE__*/ (function(A) { "use strict"; _inherits(_class, A); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; })(A); @@ -65,9 +91,10 @@ var B2 = function B2() { _classCallCheck(this, B2); this.anon = /*#__PURE__*/ (function(A) { _inherits(_class, A); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; })(A); @@ -76,9 +103,10 @@ function B3() { return /*#__PURE__*/ (function(A) { "use strict"; _inherits(Inner, A); + var _super = _createSuper(Inner); function Inner() { _classCallCheck(this, Inner); - return _possibleConstructorReturn(this, _getPrototypeOf(Inner).apply(this, arguments)); + return _super.apply(this, arguments); } return Inner; })(A); @@ -87,18 +115,20 @@ var K = // extends can call B /*#__PURE__*/ function(_super) { "use strict"; _inherits(K, _super); + var _super1 = _createSuper(K); function K() { _classCallCheck(this, K); - return _possibleConstructorReturn(this, _getPrototypeOf(K).apply(this, arguments)); + return _super1.apply(this, arguments); } return K; }(B1()); var C = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C, _super); + var _super2 = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super2.apply(this, arguments); } return C; }(new B2().anon); @@ -106,9 +136,10 @@ var b3Number1 = B3(); var S = /*#__PURE__*/ function(b3Number) { "use strict"; _inherits(S, b3Number); + var _super = _createSuper(S); function S() { _classCallCheck(this, S); - return _possibleConstructorReturn(this, _getPrototypeOf(S).apply(this, arguments)); + return _super.apply(this, arguments); } return S; }(b3Number1); diff --git a/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.2.minified/output.js index b847ef2f538..82c79315af2 100644 --- a/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/classExpressions/genericClassExpressionInFunction/input.ts/es5.2.minified/output.js @@ -16,63 +16,91 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B2 = function() { "use strict"; _classCallCheck(this, B2), this.anon = (function(A) { + _inherits(_class, A); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, A), _class; + return _class; })(A1); }, K = function(_super) { "use strict"; + _inherits(K, _super); + var _super1 = _createSuper(K); function K() { - return _classCallCheck(this, K), _possibleConstructorReturn(this, _getPrototypeOf(K).apply(this, arguments)); + return _classCallCheck(this, K), _super1.apply(this, arguments); } - return _inherits(K, _super), K; + return K; }(function() { return (function(A) { "use strict"; + _inherits(_class, A); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, A), _class; + return _class; })(A1); }()), C = function(_super) { "use strict"; + _inherits(C, _super); + var _super2 = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super2.apply(this, arguments); } - return _inherits(C, _super), C; + return C; }(new B2().anon), S = function(b3Number) { "use strict"; + _inherits(S, b3Number); + var _super = _createSuper(S); function S() { - return _classCallCheck(this, S), _possibleConstructorReturn(this, _getPrototypeOf(S).apply(this, arguments)); + return _classCallCheck(this, S), _super.apply(this, arguments); } - return _inherits(S, b3Number), S; + return S; }(function() { return (function(A) { "use strict"; + _inherits(Inner, A); + var _super = _createSuper(Inner); function Inner() { - return _classCallCheck(this, Inner), _possibleConstructorReturn(this, _getPrototypeOf(Inner).apply(this, arguments)); + return _classCallCheck(this, Inner), _super.apply(this, arguments); } - return _inherits(Inner, A), Inner; + return Inner; })(A1); }()), c = new C(), k = new K(), s = new S(); c.genericVar = 12, k.genericVar = 12, s.genericVar = 12; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.1.normal/output.js index c28c440a519..015316440e2 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.1.normal/output.js @@ -44,27 +44,53 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); this.a = 1; this.a = x; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 1; _this.y = 'hello'; return _this; } - return Derived; + return Derived1; }(Base); -var r = new Derived(); // error -var r2 = new Derived(1); +var r = new Derived1(); // error +var r2 = new Derived1(1); var Base2 = function Base2(x) { "use strict"; _classCallCheck(this, Base2); @@ -73,10 +99,11 @@ var Base2 = function Base2(x) { var D = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D, Base2); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 2; _this.y = null; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.2.minified/output.js index 8ae72079963..c8466bf3890 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor/input.ts/es5.2.minified/output.js @@ -16,40 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(x) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function(x) { "use strict"; _classCallCheck(this, Base1), this.a = 1, this.a = x; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { var _this; - return _classCallCheck(this, Derived), _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)), _this.x = 1, _this.y = "hello", _this; + return _classCallCheck(this, Derived1), _this = _super.apply(this, arguments), _this.x = 1, _this.y = "hello", _this; } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1); -new Derived(), new Derived(1); +new Derived1(), new Derived1(1); var Base21 = function(x) { "use strict"; _classCallCheck(this, Base21), this.a = x; }, D = function(Base2) { "use strict"; + _inherits(D, Base2); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this.x = 2, _this.y = null, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this.x = 2, _this.y = null, _this; } - return _inherits(D, Base2), D; + return D; }(Base21); new D(), new D(new Date()); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.1.normal/output.js index 2c80570ff6f..b98d3d66486 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.1.normal/output.js @@ -44,29 +44,55 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); this.a = 1; this.a = x; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 1; _this.y = 'hello'; return _this; } - return Derived; + return Derived1; }(Base); -var r = new Derived(); // error -var r2 = new Derived(1); -var r3 = new Derived(1, 2); -var r4 = new Derived(1, 2, 3); +var r = new Derived1(); // error +var r2 = new Derived1(1); +var r3 = new Derived1(1, 2); +var r4 = new Derived1(1, 2, 3); var Base2 = function Base2(x) { "use strict"; _classCallCheck(this, Base2); @@ -75,10 +101,11 @@ var Base2 = function Base2(x) { var D = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D, Base2); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 2; _this.y = null; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.2.minified/output.js index 12acd7d2e7d..864fd947c0d 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor2/input.ts/es5.2.minified/output.js @@ -16,40 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(x) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function(x) { "use strict"; _classCallCheck(this, Base1), this.a = 1, this.a = x; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { var _this; - return _classCallCheck(this, Derived), _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)), _this.x = 1, _this.y = "hello", _this; + return _classCallCheck(this, Derived1), _this = _super.apply(this, arguments), _this.x = 1, _this.y = "hello", _this; } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1); -new Derived(), new Derived(1), new Derived(1, 2), new Derived(1, 2, 3); +new Derived1(), new Derived1(1), new Derived1(1, 2), new Derived1(1, 2, 3); var Base21 = function(x) { "use strict"; _classCallCheck(this, Base21), this.a = x; }, D = function(Base2) { "use strict"; + _inherits(D, Base2); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this.x = 2, _this.y = null, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this.x = 2, _this.y = null, _this; } - return _inherits(D, Base2), D; + return D; }(Base21); new D(), new D(new Date()), new D(new Date(), new Date()), new D(new Date(), new Date(), new Date()); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.1.normal/output.js index 603de944e57..80cfa08dc30 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); @@ -51,35 +76,37 @@ var Base = function Base(x) { this.a = 1; this.a = x; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(y, z) { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(y, z) { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, 2)); + _this = _super.call(this, 2); _this.b = ''; _this.b = y; return _this; } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 1; _this.y = 'hello'; return _this; } return Derived2; -}(Derived); -var r = new Derived(); // error +}(Derived1); +var r = new Derived1(); // error var r2 = new Derived2(1); // error -var r3 = new Derived('', ''); +var r3 = new Derived1('', ''); var Base2 = function Base2(x) { "use strict"; _classCallCheck(this, Base2); @@ -88,10 +115,11 @@ var Base2 = function Base2(x) { var D = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D, Base); + var _super = _createSuper(D); function D(y, z) { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, 2)); + _this = _super.call(this, 2); _this.b = null; _this.b = y; return _this; @@ -101,10 +129,11 @@ var D = /*#__PURE__*/ function(Base) { var D2 = /*#__PURE__*/ function(D) { "use strict"; _inherits(D2, D); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 2; _this.y = null; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.2.minified/output.js index 322b948b4f3..c4898b7456a 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/automaticConstructors/derivedClassWithoutExplicitConstructor3/input.ts/es5.2.minified/output.js @@ -16,54 +16,78 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(x) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function(x) { "use strict"; _classCallCheck(this, Base1), this.a = 1, this.a = x; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived(y, z) { + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(y, z) { var _this; - return _classCallCheck(this, Derived), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, 2))).b = "", _this.b = y, _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this, 2)).b = "", _this.b = y, _this; } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { var _this; - return _classCallCheck(this, Derived2), _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)), _this.x = 1, _this.y = "hello", _this; + return _classCallCheck(this, Derived2), _this = _super.apply(this, arguments), _this.x = 1, _this.y = "hello", _this; } - return _inherits(Derived2, Derived), Derived2; -}(Derived); -new Derived(), new Derived2(1), new Derived("", ""); + return Derived2; +}(Derived1); +new Derived1(), new Derived2(1), new Derived1("", ""); var Base2 = function(x) { "use strict"; _classCallCheck(this, Base2), this.a = x; }, D = function(Base) { "use strict"; + _inherits(D, Base); + var _super = _createSuper(D); function D(y, z) { var _this; - return _classCallCheck(this, D), (_this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, 2))).b = null, _this.b = y, _this; + return _classCallCheck(this, D), (_this = _super.call(this, 2)).b = null, _this.b = y, _this; } - return _inherits(D, Base), D; + return D; }(Base1), D2 = function(D) { "use strict"; + _inherits(D2, D); + var _super = _createSuper(D2); function D2() { var _this; - return _classCallCheck(this, D2), _this = _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)), _this.x = 2, _this.y = null, _this; + return _classCallCheck(this, D2), _this = _super.apply(this, arguments), _this.x = 2, _this.y = null, _this; } - return _inherits(D2, D), D2; + return D2; }(D); new D2(), new D2(new Date()), new D2(new Date(), new Date()); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.1.normal/output.js index 720335da338..749d1e9635d 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var BaseA = // @declaration: true /*#__PURE__*/ function() { "use strict"; @@ -117,10 +142,11 @@ var BaseC = /*#__PURE__*/ function() { var DerivedA = /*#__PURE__*/ function(BaseA1) { "use strict"; _inherits(DerivedA, BaseA1); + var _super = _createSuper(DerivedA); function DerivedA(x) { _classCallCheck(this, DerivedA); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedA).call(this, x)); + _this = _super.call(this, x); _this.x = x; return _this; } @@ -150,10 +176,11 @@ var DerivedA = /*#__PURE__*/ function(BaseA1) { var DerivedB = /*#__PURE__*/ function(BaseB1) { "use strict"; _inherits(DerivedB, BaseB1); + var _super = _createSuper(DerivedB); function DerivedB(x) { _classCallCheck(this, DerivedB); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedB).call(this, x)); + _this = _super.call(this, x); _this.x = x; return _this; } @@ -183,10 +210,11 @@ var DerivedB = /*#__PURE__*/ function(BaseB1) { var DerivedC = /*#__PURE__*/ function(BaseC1) { "use strict"; _inherits(DerivedC, BaseC1); + var _super = _createSuper(DerivedC); function DerivedC(x) { _classCallCheck(this, DerivedC); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedC).call(this, x)); + _this = _super.call(this, x); _this.x = x; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.2.minified/output.js index d24208cb0ff..dfe16cce155 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility2/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, BaseA = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var BaseA = function() { "use strict"; function BaseA(x) { _classCallCheck(this, BaseA), this.x = x; @@ -86,11 +102,13 @@ var _typeof = function(obj) { ]), BaseC; }(), DerivedA = function(BaseA1) { "use strict"; + _inherits(DerivedA, BaseA1); + var _super = _createSuper(DerivedA); function DerivedA(x) { var _this; - return _classCallCheck(this, DerivedA), (_this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedA).call(this, x))).x = x, _this; + return _classCallCheck(this, DerivedA), (_this = _super.call(this, x)).x = x, _this; } - return _inherits(DerivedA, BaseA1), _createClass(DerivedA, [ + return _createClass(DerivedA, [ { key: "createInstance", value: function() { @@ -113,11 +131,13 @@ var _typeof = function(obj) { ]), DerivedA; }(BaseA), DerivedB = function(BaseB1) { "use strict"; + _inherits(DerivedB, BaseB1); + var _super = _createSuper(DerivedB); function DerivedB(x) { var _this; - return _classCallCheck(this, DerivedB), (_this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedB).call(this, x))).x = x, _this; + return _classCallCheck(this, DerivedB), (_this = _super.call(this, x)).x = x, _this; } - return _inherits(DerivedB, BaseB1), _createClass(DerivedB, [ + return _createClass(DerivedB, [ { key: "createInstance", value: function() { @@ -140,11 +160,13 @@ var _typeof = function(obj) { ]), DerivedB; }(BaseB), DerivedC = function(BaseC1) { "use strict"; + _inherits(DerivedC, BaseC1); + var _super = _createSuper(DerivedC); function DerivedC(x) { var _this; - return _classCallCheck(this, DerivedC), (_this = _possibleConstructorReturn(this, _getPrototypeOf(DerivedC).call(this, x))).x = x, _this; + return _classCallCheck(this, DerivedC), (_this = _super.call(this, x)).x = x, _this; } - return _inherits(DerivedC, BaseC1), _createClass(DerivedC, [ + return _createClass(DerivedC, [ { key: "createInstance", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.1.normal/output.js index a4066950dc2..0bcd35952c5 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A1 = // @declaration: true /*#__PURE__*/ function() { "use strict"; @@ -84,9 +109,10 @@ var A1 = // @declaration: true }(); var C = /*#__PURE__*/ function(A) { _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A1); @@ -120,9 +146,10 @@ var D1 = /*#__PURE__*/ function() { }(); var F = /*#__PURE__*/ function(D) { _inherits(F, D); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); - return _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _super.apply(this, arguments); } return F; }(D1); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.2.minified/output.js index 5ae7cb2af89..f5178fa7ba9 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility4/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; function A1() { _classCallCheck(this, A1); @@ -60,10 +76,12 @@ var _typeof = function(obj) { } ]), B; }(), C = function(A) { + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), C; + return C; }(A1); } } @@ -90,10 +108,12 @@ var _typeof = function(obj) { } ]), E; }(), F = function(D) { + _inherits(F, D); + var _super = _createSuper(F); function F() { - return _classCallCheck(this, F), _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _classCallCheck(this, F), _super.apply(this, arguments); } - return _inherits(F, D), F; + return F; }(D1); } } diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.1.normal/output.js index 256373dd50e..b5e640e4467 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.1.normal/output.js @@ -58,18 +58,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base1) { +var Derived1 = /*#__PURE__*/ function(Base1) { "use strict"; - _inherits(Derived, Base1); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, null, [ + _createClass(Derived1, null, [ { key: "make", value: function make() { @@ -77,7 +103,7 @@ var Derived = /*#__PURE__*/ function(Base1) { } // ok } ]); - return Derived; + return Derived1; }(Base); var Unrelated = /*#__PURE__*/ function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.2.minified/output.js index fa43e21c3f4..533eb791b51 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorAccessibility5/input.ts/es5.2.minified/output.js @@ -23,16 +23,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -41,14 +34,42 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, null, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, null, [ { key: "make", value: function() { new Base1(); } } - ]), Derived; + ]), Derived1; }(Base1), Unrelated = function() { "use strict"; function Unrelated() { diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.1.normal/output.js index 998b71de104..98821a2f8fe 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = function C1(x) { "use strict"; _classCallCheck(this, C1); @@ -68,15 +93,16 @@ var C3 = function C3(p) { var c3; c3.p // protected, error ; -var Derived = /*#__PURE__*/ function(C3) { +var Derived1 = /*#__PURE__*/ function(C3) { "use strict"; - _inherits(Derived, C3); - function Derived(p) { - _classCallCheck(this, Derived); + _inherits(Derived1, C3); + var _super = _createSuper(Derived1); + function Derived1(p) { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, p)); + _this = _super.call(this, p); _this.p; // OK return _this; } - return Derived; + return Derived1; }(C3); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.2.minified/output.js index db6e8a414ef..7407c9d9abb 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility/input.ts/es5.2.minified/output.js @@ -26,16 +26,9 @@ var C31 = function(p) { _classCallCheck(this, C31), this.p = p; }; c3.p; -var Derived = function(C3) { +var Derived1 = function(C3) { "use strict"; - function Derived(p) { - var _this, self, call, obj; - return _classCallCheck(this, Derived), (_this = (self = this, (call = _getPrototypeOf(Derived).call(this, p)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,5 +37,34 @@ var Derived = function(C3) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, C3), Derived; + }(Derived1, C3); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1(p) { + var _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this, p)).p, _this; + } + return Derived1; }(C31); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.1.normal/output.js index 998b71de104..98821a2f8fe 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = function C1(x) { "use strict"; _classCallCheck(this, C1); @@ -68,15 +93,16 @@ var C3 = function C3(p) { var c3; c3.p // protected, error ; -var Derived = /*#__PURE__*/ function(C3) { +var Derived1 = /*#__PURE__*/ function(C3) { "use strict"; - _inherits(Derived, C3); - function Derived(p) { - _classCallCheck(this, Derived); + _inherits(Derived1, C3); + var _super = _createSuper(Derived1); + function Derived1(p) { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, p)); + _this = _super.call(this, p); _this.p; // OK return _this; } - return Derived; + return Derived1; }(C3); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.2.minified/output.js index db6e8a414ef..7407c9d9abb 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility2/input.ts/es5.2.minified/output.js @@ -26,16 +26,9 @@ var C31 = function(p) { _classCallCheck(this, C31), this.p = p; }; c3.p; -var Derived = function(C3) { +var Derived1 = function(C3) { "use strict"; - function Derived(p) { - var _this, self, call, obj; - return _classCallCheck(this, Derived), (_this = (self = this, (call = _getPrototypeOf(Derived).call(this, p)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,5 +37,34 @@ var Derived = function(C3) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, C3), Derived; + }(Derived1, C3); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1(p) { + var _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this, p)).p, _this; + } + return Derived1; }(C31); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.1.normal/output.js index c9c4cc0880a..9df2f463abe 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.1.normal/output.js @@ -44,23 +44,49 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(p) { "use strict"; _classCallCheck(this, Base); this.p = p; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(p) { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(p) { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, p)); + _this = _super.call(this, p); _this.p = p; _this.p; // OK return _this; } - return Derived; + return Derived1; }(Base); var d; d.p; // public, OK diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.2.minified/output.js index 52d167ebfe2..98296eb9b8d 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/classConstructorParametersAccessibility3/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var d, Base1 = function(p) { "use strict"; _classCallCheck(this, Base1), this.p = p; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived(p) { - var _this, self, call, obj; - return _classCallCheck(this, Derived), (_this = (self = this, (call = _getPrototypeOf(Derived).call(this, p)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p = p, _this.p, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,6 +25,35 @@ var d, Base1 = function(p) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1(p) { + var _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this, p)).p = p, _this.p, _this; + } + return Derived1; }(Base1); d.p; // public, OK diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.1.normal/output.js index d9eea855fdd..1142eefa526 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A(x) { "use strict"; _classCallCheck(this, A); @@ -53,10 +78,11 @@ var A = function A(x) { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B(x) { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this, x)); + _this = _super.call(this, x); // Fails, x is readonly _this.x = 1; return _this; @@ -66,10 +92,11 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C(x) { _classCallCheck(this, C); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this, x)); + _this = _super.call(this, x); _this.x = x; _this.x = 1; return _this; @@ -86,10 +113,11 @@ var E = // Fails, can't redeclare readonly property /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E(x) { _classCallCheck(this, E); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(E).call(this, x)); + _this = _super.call(this, x); _this.x = x; _this.x = 1; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.2.minified/output.js index d6da1c5c331..79056558e62 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment/input.ts/es5.2.minified/output.js @@ -16,44 +16,66 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function(x) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function(x) { "use strict"; _classCallCheck(this, A1), this.x = x, this.x = 0; }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B(x) { var _this; - return _classCallCheck(this, B), (_this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this, x))).x = 1, _this; + return _classCallCheck(this, B), (_this = _super.call(this, x)).x = 1, _this; } - return _inherits(B, A), B; + return B; }(A1), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C(x) { var _this; - return _classCallCheck(this, C), (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this, x))).x = x, _this.x = 1, _this; + return _classCallCheck(this, C), (_this = _super.call(this, x)).x = x, _this.x = 1, _this; } - return _inherits(C, A), C; + return C; }(A1), D1 = function(x) { "use strict"; _classCallCheck(this, D1), this.x = x, this.x = 0; }, E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E(x) { var _this; - return _classCallCheck(this, E), (_this = _possibleConstructorReturn(this, _getPrototypeOf(E).call(this, x))).x = x, _this.x = 1, _this; + return _classCallCheck(this, E), (_this = _super.call(this, x)).x = x, _this.x = 1, _this; } - return _inherits(E, D), E; + return E; }(D1); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.1.normal/output.js index 26fadb462fc..9c7c47958dc 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.1.normal/output.js @@ -44,19 +44,45 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; return _possibleConstructorReturn(_this); } - return Derived; + return Derived1; }(Base); var Base2 = function Base2() { "use strict"; @@ -65,12 +91,13 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { var _this = this; _classCallCheck(this, Derived2); var _this1; var r2 = function() { - return _this1 = _possibleConstructorReturn(_this, _getPrototypeOf(Derived2).call(_this)); + return _this1 = _super.call(_this); }; // error for misplaced super call (nested function) return _possibleConstructorReturn(_this1); } @@ -79,12 +106,13 @@ var Derived2 = /*#__PURE__*/ function(Base2) { var Derived3 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived3, Base2); + var _super = _createSuper(Derived3); function Derived3() { _classCallCheck(this, Derived3); var _this = this; var _this2; var r = function r() { - _this2 = _possibleConstructorReturn(_this, _getPrototypeOf(Derived3).call(_this)); + _this2 = _super.call(_this); } // error ; return _possibleConstructorReturn(_this2); @@ -94,10 +122,11 @@ var Derived3 = /*#__PURE__*/ function(Base2) { var Derived4 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived4, Base2); + var _super = _createSuper(Derived4); function Derived4() { _classCallCheck(this, Derived4); var _this; - var r = _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived4).call(this)); // ok + var r = _this = _super.call(this); // ok return _possibleConstructorReturn(_this); } return Derived4; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.2.minified/output.js index 4fc6754111b..752c27534be 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall/input.ts/es5.2.minified/output.js @@ -29,16 +29,38 @@ function _setPrototypeOf(o, p) { } var _typeof = function(obj) { return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return _possibleConstructorReturn(this, result); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { + function Derived1() { var _this; - return _classCallCheck(this, Derived), _possibleConstructorReturn(_this); + return _classCallCheck(this, Derived1), _possibleConstructorReturn(_this); } - return _inherits(Derived, Base), Derived; + return _inherits(Derived1, Base), _createSuper(Derived1), Derived1; }(Base1), Base21 = function() { "use strict"; _classCallCheck(this, Base21); @@ -48,18 +70,19 @@ var _typeof = function(obj) { var _this; return _classCallCheck(this, Derived2), _possibleConstructorReturn(_this); } - return _inherits(Derived2, Base2), Derived2; + return _inherits(Derived2, Base2), _createSuper(Derived2), Derived2; }(Base21), Derived3 = function(Base2) { "use strict"; function Derived3() { return _classCallCheck(this, Derived3), _possibleConstructorReturn(void 0); } - return _inherits(Derived3, Base2), Derived3; + return _inherits(Derived3, Base2), _createSuper(Derived3), Derived3; }(Base21), Derived4 = function(Base2) { "use strict"; + _inherits(Derived4, Base2); + var _super = _createSuper(Derived4); function Derived4() { - var _this; - return _classCallCheck(this, Derived4), _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived4).call(this)), _possibleConstructorReturn(_this); + return _classCallCheck(this, Derived4), _possibleConstructorReturn(_super.call(this)); } - return _inherits(Derived4, Base2), Derived4; + return Derived4; }(Base21); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.1.normal/output.js index a250d3f6489..6d4fa3cea92 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -51,11 +76,12 @@ var Base = function Base() { var Sub = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Sub, Base); + var _super = _createSuper(Sub); function Sub(p) { _classCallCheck(this, Sub); var _this; console.log('hi'); // should emit before super - _this = _possibleConstructorReturn(this, _getPrototypeOf(Sub).call(this)); + _this = _super.call(this); _this.p = p; _this.field = 0; return _this; @@ -65,11 +91,12 @@ var Sub = /*#__PURE__*/ function(Base) { var Test = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Test, Base); + var _super = _createSuper(Test); function Test(p) { _classCallCheck(this, Test); var _this; 1; // should emit before super - _this = _possibleConstructorReturn(this, _getPrototypeOf(Test).call(this)); + _this = _super.call(this); _this.p = p; _this.prop = 1; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.2.minified/output.js index bf4d97cf9df..883afeae8fa 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Sub = function(Base) { "use strict"; + _inherits(Sub, Base); + var _super = _createSuper(Sub); function Sub(p) { var _this; - return _classCallCheck(this, Sub), console.log("hi"), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Sub).call(this))).p = p, _this.field = 0, _this; + return _classCallCheck(this, Sub), console.log("hi"), (_this = _super.call(this)).p = p, _this.field = 0, _this; } - return _inherits(Sub, Base), Sub; + return Sub; }(Base1), Test = function(Base) { "use strict"; + _inherits(Test, Base); + var _super = _createSuper(Test); function Test(p) { var _this; - return _classCallCheck(this, Test), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Test).call(this))).p = p, _this.prop = 1, _this; + return _classCallCheck(this, Test), (_this = _super.call(this)).p = p, _this.prop = 1, _this; } - return _inherits(Test, Base), Test; + return Test; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.1.normal/output.js index 83121e91e42..59d32728a63 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -51,11 +76,12 @@ var Base = function Base() { var Sub = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Sub, Base); + var _super = _createSuper(Sub); function Sub(p) { _classCallCheck(this, Sub); var _this; console.log('hi'); - _this = _possibleConstructorReturn(this, _getPrototypeOf(Sub).call(this)); + _this = _super.call(this); _this.p = p; _this.field = 0; return _this; @@ -65,11 +91,12 @@ var Sub = /*#__PURE__*/ function(Base) { var Test = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Test, Base); + var _super = _createSuper(Test); function Test(p) { _classCallCheck(this, Test); var _this; 1; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Test).call(this)); + _this = _super.call(this); _this.p = p; _this.prop = 1; return _this; diff --git a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.2.minified/output.js index bf4d97cf9df..883afeae8fa 100644 --- a/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Sub = function(Base) { "use strict"; + _inherits(Sub, Base); + var _super = _createSuper(Sub); function Sub(p) { var _this; - return _classCallCheck(this, Sub), console.log("hi"), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Sub).call(this))).p = p, _this.field = 0, _this; + return _classCallCheck(this, Sub), console.log("hi"), (_this = _super.call(this)).p = p, _this.field = 0, _this; } - return _inherits(Sub, Base), Sub; + return Sub; }(Base1), Test = function(Base) { "use strict"; + _inherits(Test, Base); + var _super = _createSuper(Test); function Test(p) { var _this; - return _classCallCheck(this, Test), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Test).call(this))).p = p, _this.prop = 1, _this; + return _classCallCheck(this, Test), (_this = _super.call(this)).p = p, _this.prop = 1, _this; } - return _inherits(Test, Base), Test; + return Test; }(Base1); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.1.normal/output.js index eb07094f1a1..d6218a4015f 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var K = /*#__PURE__*/ function() { "use strict"; function K() { @@ -82,9 +107,10 @@ var K = /*#__PURE__*/ function() { var C = /*#__PURE__*/ function(K) { "use strict"; _inherits(C, K); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.2.minified/output.js index 62e660a8f3f..0ea28395801 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateProtectedMembersAreNotAccessibleDestructuring/input.ts/es5.2.minified/output.js @@ -42,14 +42,7 @@ var K = function() { ]), K; }(), C = function(K) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -58,7 +51,35 @@ var K = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, K), _createClass(C, [ + }(C, K); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: "m2", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.1.normal/output.js index b123d031ae4..d1faacb771e 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.1.normal/output.js @@ -44,23 +44,49 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base1) { +var Derived1 = /*#__PURE__*/ function(Base1) { "use strict"; - _inherits(Derived, Base1); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.bing // error = function() { return Base.foo; }; return _this; } - return Derived; + return Derived1; }(Base); -Derived.bar = Base.foo; +Derived1.bar = Base.foo; diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.2.minified/output.js index 135d86ec283..beb0d1da447 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticMemberAccessibility/input.ts/es5.2.minified/output.js @@ -11,21 +11,12 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Base = function() { +var Base1 = function() { "use strict"; - _classCallCheck(this, Base); -}, Derived = function(Base1) { + _classCallCheck(this, Base1); +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var _this, self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).bing = function() { - return Base.foo; - }, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,6 +25,37 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base1), Derived; -}(Base); -Derived.bar = Base.foo; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + var _this; + return _classCallCheck(this, Derived1), _this = _super.apply(this, arguments), _this.bing = function() { + return Base1.foo; + }, _this; + } + return Derived1; +}(Base1); +Derived1.bar = Base1.foo; diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.1.normal/output.js index 2d1da07a1da..06da1b01c95 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.2.minified/output.js index bf0c4aa003c..937db17c9ac 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/privateStaticNotAccessibleInClodule2/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ var _typeof = function(obj) { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - function D() { - var self, call; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,7 +27,35 @@ var _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); (D || (D = { })).y = D.bar; diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.1.normal/output.js index 1c52684ca8c..5984f9a311b 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -65,9 +90,10 @@ var B = function B() { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { @@ -141,9 +167,10 @@ var C = /*#__PURE__*/ function(B) { var E = /*#__PURE__*/ function(C) { "use strict"; _inherits(E, C); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } return E; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.2.minified/output.js index 289bc9f80be..fc005fcc958 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, B1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var B1 = function() { "use strict"; _classCallCheck(this, B1); }, C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), _createClass(C, [ + return _createClass(C, [ { key: "y", get: function() { @@ -106,8 +124,10 @@ var _typeof = function(obj) { ]), C; }(B1), E = function(C) { "use strict"; + _inherits(E, C); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, C), E; + return E; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.1.normal/output.js index 1fa4a8f8316..f505e6e9e1a 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -98,9 +123,10 @@ var Base = /*#__PURE__*/ function() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived1, [ { @@ -137,9 +163,10 @@ var Derived1 = /*#__PURE__*/ function(Base) { var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived2, [ { @@ -176,9 +203,10 @@ var Derived2 = /*#__PURE__*/ function(Base) { var Derived3 = /*#__PURE__*/ function(Derived1) { "use strict"; _inherits(Derived3, Derived1); + var _super = _createSuper(Derived3); function Derived3() { _classCallCheck(this, Derived3); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived3, [ { @@ -215,9 +243,10 @@ var Derived3 = /*#__PURE__*/ function(Derived1) { var Derived4 = /*#__PURE__*/ function(Derived2) { "use strict"; _inherits(Derived4, Derived2); + var _super = _createSuper(Derived4); function Derived4() { _classCallCheck(this, Derived4); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived4).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived4, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.2.minified/output.js index b383ace6494..50d69c3137b 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, d11, d21, d31, d41, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, d11, d21, d31, d41, Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -66,10 +82,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Base; }(), Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), _createClass(Derived1, [ + return _createClass(Derived1, [ { key: "method1", value: function() { @@ -92,10 +110,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived1; }(Base), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), _createClass(Derived2, [ + return _createClass(Derived2, [ { key: "method2", value: function() { @@ -118,10 +138,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived2; }(Base), Derived3 = function(Derived1) { "use strict"; + _inherits(Derived3, Derived1); + var _super = _createSuper(Derived3); function Derived3() { - return _classCallCheck(this, Derived3), _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _classCallCheck(this, Derived3), _super.apply(this, arguments); } - return _inherits(Derived3, Derived1), _createClass(Derived3, [ + return _createClass(Derived3, [ { key: "method3", value: function() { @@ -144,10 +166,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived3; }(Derived1), Derived4 = function(Derived2) { "use strict"; + _inherits(Derived4, Derived2); + var _super = _createSuper(Derived4); function Derived4() { - return _classCallCheck(this, Derived4), _possibleConstructorReturn(this, _getPrototypeOf(Derived4).apply(this, arguments)); + return _classCallCheck(this, Derived4), _super.apply(this, arguments); } - return _inherits(Derived4, Derived2), _createClass(Derived4, [ + return _createClass(Derived4, [ { key: "method4", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js index 2a9f5d59630..645b08da9b2 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -65,9 +90,10 @@ var B = function B() { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js index 463964a8652..d52845b24c0 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var B1 = function() { _classCallCheck(this, B1); }, C = function(B) { "use strict"; - var Constructor, protoProps, staticProps; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var B1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, B), Constructor = C, protoProps = [ + }(C, B); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return Constructor = C, protoProps = [ { key: "y", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js index ae1e1555d71..262b54cb23e 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -85,9 +110,10 @@ var Base = /*#__PURE__*/ function() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived1, [ { @@ -111,9 +137,10 @@ var Derived1 = /*#__PURE__*/ function(Base) { var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived2, [ { @@ -137,9 +164,10 @@ var Derived2 = /*#__PURE__*/ function(Base) { var Derived3 = /*#__PURE__*/ function(Derived1) { "use strict"; _inherits(Derived3, Derived1); + var _super = _createSuper(Derived3); function Derived3() { _classCallCheck(this, Derived3); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived3, [ { @@ -163,9 +191,10 @@ var Derived3 = /*#__PURE__*/ function(Derived1) { var Derived4 = /*#__PURE__*/ function(Derived2) { "use strict"; _inherits(Derived4, Derived2); + var _super = _createSuper(Derived4); function Derived4() { _classCallCheck(this, Derived4); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived4).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived4, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js index 8907484f6cd..a816911ad31 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, d11, d21, d31, d41, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, d11, d21, d31, d41, Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -54,10 +70,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Base; }(), Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), _createClass(Derived1, [ + return _createClass(Derived1, [ { key: "method1", value: function() { @@ -68,10 +86,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived1; }(Base), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), _createClass(Derived2, [ + return _createClass(Derived2, [ { key: "method2", value: function() { @@ -82,10 +102,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived2; }(Base), Derived3 = function(Derived1) { "use strict"; + _inherits(Derived3, Derived1); + var _super = _createSuper(Derived3); function Derived3() { - return _classCallCheck(this, Derived3), _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _classCallCheck(this, Derived3), _super.apply(this, arguments); } - return _inherits(Derived3, Derived1), _createClass(Derived3, [ + return _createClass(Derived3, [ { key: "method3", value: function() { @@ -96,10 +118,12 @@ var b, d11, d21, d31, d41, _typeof = function(obj) { ]), Derived3; }(Derived1), Derived4 = function(Derived2) { "use strict"; + _inherits(Derived4, Derived2); + var _super = _createSuper(Derived4); function Derived4() { - return _classCallCheck(this, Derived4), _possibleConstructorReturn(this, _getPrototypeOf(Derived4).apply(this, arguments)); + return _classCallCheck(this, Derived4), _super.apply(this, arguments); } - return _inherits(Derived4, Derived2), _createClass(Derived4, [ + return _createClass(Derived4, [ { key: "method4", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.1.normal/output.js index 5ba5daebd24..3a1829eb65e 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -96,21 +121,22 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "method1", value: function method1() { this.x; // OK, accessed within a subclass of the declaring class - _get(_getPrototypeOf(Derived.prototype), "x", this); // Error, x is not public + _get(_getPrototypeOf(Derived1.prototype), "x", this); // Error, x is not public } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.2.minified/output.js index a07801572c9..b8ad9a50216 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3/input.ts/es5.2.minified/output.js @@ -46,16 +46,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,12 +57,40 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "method1", value: function() { - this.x, _get(_getPrototypeOf(Derived.prototype), "x", this); + this.x, _get(_getPrototypeOf(Derived1.prototype), "x", this); } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.1.normal/output.js index 7c7c4352d01..025867d9ea8 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -99,9 +124,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -138,9 +164,10 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.2.minified/output.js index 297731249f8..3e366aba234 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedInstanceMemberAccessibility/input.ts/es5.2.minified/output.js @@ -34,12 +34,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -49,9 +43,31 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -66,10 +82,12 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "g", value: function() { @@ -80,8 +98,10 @@ var _typeof = function(obj) { ]), B; }(A), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), C; + return C; }(A); diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js index 72d692ce127..9d762928ed8 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -79,9 +104,10 @@ var Base = /*#__PURE__*/ function() { var Derived1 = /*#__PURE__*/ function(Base1) { "use strict"; _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived1, null, [ { @@ -99,9 +125,10 @@ var Derived1 = /*#__PURE__*/ function(Base1) { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived2, null, [ { @@ -119,9 +146,10 @@ var Derived2 = /*#__PURE__*/ function(Base2) { var Derived3 = /*#__PURE__*/ function(Derived11) { "use strict"; _inherits(Derived3, Derived11); + var _super = _createSuper(Derived3); function Derived3() { _classCallCheck(this, Derived3); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived3, null, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js index d395225bccb..8389c59a703 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -53,10 +69,12 @@ var _typeof = function(obj) { ]), Base; }(), Derived1 = function(Base1) { "use strict"; + _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base1), _createClass(Derived1, null, [ + return _createClass(Derived1, null, [ { key: "staticMethod1", value: function() { @@ -66,10 +84,12 @@ var _typeof = function(obj) { ]), Derived1; }(Base), Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), _createClass(Derived2, null, [ + return _createClass(Derived2, null, [ { key: "staticMethod2", value: function() { @@ -79,10 +99,12 @@ var _typeof = function(obj) { ]), Derived2; }(Base), Derived3 = function(Derived1) { "use strict"; + _inherits(Derived3, Derived1); + var _super = _createSuper(Derived3); function Derived3() { - return _classCallCheck(this, Derived3), _possibleConstructorReturn(this, _getPrototypeOf(Derived3).apply(this, arguments)); + return _classCallCheck(this, Derived3), _super.apply(this, arguments); } - return _inherits(Derived3, Derived1), _createClass(Derived3, null, [ + return _createClass(Derived3, null, [ { key: "staticMethod3", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js index da361017408..7675441b649 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -99,9 +124,10 @@ var Base = /*#__PURE__*/ function() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived1, null, [ { @@ -117,9 +143,10 @@ var Derived1 = /*#__PURE__*/ function(Base) { var Derived2 = /*#__PURE__*/ function(Derived1) { "use strict"; _inherits(Derived2, Derived1); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Derived2, null, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js index 974efa02013..7def54afc54 100644 --- a/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2/input.ts/es5.2.minified/output.js @@ -34,12 +34,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -49,9 +43,31 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -66,10 +82,12 @@ var _typeof = function(obj) { ]), Base; }(), Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), _createClass(Derived1, null, [ + return _createClass(Derived1, null, [ { key: "staticMethod1", value: function() { @@ -79,10 +97,12 @@ var _typeof = function(obj) { ]), Derived1; }(Base), Derived2 = function(Derived1) { "use strict"; + _inherits(Derived2, Derived1); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived1), _createClass(Derived2, null, [ + return _createClass(Derived2, null, [ { key: "staticMethod3", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.1.normal/output.js index ab55979ef96..0fc67af3325 100644 --- a/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var NonGeneric; (function(NonGeneric) { var C = /*#__PURE__*/ function() { @@ -88,9 +113,10 @@ var NonGeneric; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -132,9 +158,10 @@ var Generic; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.2.minified/output.js index ed0f3503843..af758a30fa9 100644 --- a/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/classTypes/instancePropertiesInheritedIntoClassType/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var NonGeneric, Generic; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -25,20 +26,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var NonGeneric, Generic, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(NonGeneric) { var C = function() { "use strict"; @@ -63,10 +79,12 @@ var NonGeneric, Generic, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C), d = new D(1, 2), r = d.fn(); r.x, r.y, r.y = 4, d.y(); }(NonGeneric || (NonGeneric = { @@ -94,10 +112,12 @@ var NonGeneric, Generic, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C), d = new D(1, ""), r = d.fn(); r.x, r.y, r.y = "", d.y(); })(Generic || (Generic = { diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.1.normal/output.js index 878111a95fa..3149be7e06b 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); @@ -51,9 +76,10 @@ var Base = function Base(x) { var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(Base); @@ -67,9 +93,10 @@ var Base2 = function Base2(x) { var D = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D, Base2); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(Base2); @@ -80,9 +107,10 @@ var D2 = // specialized base class /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D2, Base2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(Base2); @@ -92,9 +120,10 @@ var d4 = new D(1); // ok var D3 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D3, Base2); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.2.minified/output.js index 6150d6394fd..a5a15286948 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithBaseClassButNoConstructor/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(x) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function(x) { "use strict"; _classCallCheck(this, Base1); }, C = function(Base) { "use strict"; + _inherits(C, Base); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, Base), C; + return C; }(Base1); new C(), new C(1); var Base21 = function(x) { @@ -45,25 +63,31 @@ var Base21 = function(x) { _classCallCheck(this, Base21); }, D = function(Base2) { "use strict"; + _inherits(D, Base2); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, Base2), D; + return D; }(Base21); new D(), new D(1); var D2 = function(Base2) { "use strict"; + _inherits(D2, Base2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, Base2), D2; + return D2; }(Base21); new D(), new D(1); var D3 = function(Base2) { "use strict"; + _inherits(D3, Base2); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, Base2), D3; + return D3; }(Base21); new D(), new D(1); diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.1.normal/output.js index a77b08f5bcc..2d16932fdd4 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var NonGeneric; (function(NonGeneric) { var C = function C(x) { @@ -62,9 +87,10 @@ var NonGeneric; var D = /*#__PURE__*/ function(C2) { "use strict"; _inherits(D, C2); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C2); @@ -91,9 +117,10 @@ var Generics; var D = /*#__PURE__*/ function(C2) { "use strict"; _inherits(D, C2); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C2); diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.2.minified/output.js index 1eb3a94da37..a9571ae18ea 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithConstructors/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var NonGeneric, Generics; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,20 +17,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var NonGeneric, Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(NonGeneric) { var C = function(x) { "use strict"; @@ -43,10 +59,12 @@ var NonGeneric, Generics, _typeof = function(obj) { new C21(), new C21(""), new C21(1); var D = function(C2) { "use strict"; + _inherits(D, C2); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C2), D; + return D; }(C21); new D(), new D(1), new D(""); }(NonGeneric || (NonGeneric = { @@ -63,10 +81,12 @@ var NonGeneric, Generics, _typeof = function(obj) { new C22(), new C22(""), new C22(1, 2); var D = function(C2) { "use strict"; + _inherits(D, C2); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C2), D; + return D; }(C22); new D(), new D(1), new D(""); })(Generics || (Generics = { diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.1.normal/output.js index 57b95459e07..f83782b7922 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C(a, b) { @@ -89,9 +114,10 @@ var r3 = r.foo; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.2.minified/output.js index c4885217ff4..48945b2846c 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/classWithStaticMembers/input.ts/es5.2.minified/output.js @@ -42,14 +42,7 @@ var C = function() { r.x, r.foo; var D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -58,6 +51,34 @@ var D = function(C) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C), r = D.fn(); r.x, r.foo; diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.1.normal/output.js index 67d06887c65..637de269996 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var NonGeneric; (function(NonGeneric) { var C = function C() { @@ -53,9 +78,10 @@ var NonGeneric; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -74,9 +100,10 @@ var Generic; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.2.minified/output.js index 9c56be59fdf..56518d2a76d 100644 --- a/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/constructorFunctionTypes/constructorHasPrototypeProperty/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var NonGeneric, Generic; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,30 +17,47 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var NonGeneric, Generic, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(NonGeneric) { var C1 = function() { "use strict"; _classCallCheck(this, C1); }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C1); C1.prototype.foo, D.prototype.bar; }(NonGeneric || (NonGeneric = { @@ -49,10 +67,12 @@ var NonGeneric, Generic, _typeof = function(obj) { _classCallCheck(this, C2); }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C2); C2.prototype.foo, D.prototype.baz; })(Generic || (Generic = { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.1.normal/output.js index eed1ef2c05b..574f907b096 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -75,15 +100,16 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = // error +var Derived1 = // error /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "x", value: function x() { @@ -91,5 +117,5 @@ var Derived = // error } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.2.minified/output.js index db8b9ae0e4b..cfc534a6b62 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor/input.ts/es5.2.minified/output.js @@ -35,16 +35,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -53,12 +46,40 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "x", value: function() { return 1; } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.1.normal/output.js index 62ddd66d4f7..9b601d482fa 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base(x) { @@ -94,24 +119,25 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); -var d = new Derived(1); +var d = new Derived1(1); var r1 = d.a; var r2 = d.b(); var r3 = d.c; d.c = ''; -var r4 = Derived.r; -var r5 = Derived.s(); -var r6 = Derived.t; -Derived.t = ''; +var r4 = Derived1.r; +var r5 = Derived1.s(); +var r6 = Derived1.t; +Derived1.t = ''; var Base2 = function Base2() { "use strict"; _classCallCheck(this, Base2); @@ -119,9 +145,10 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.2.minified/output.js index 7fc008e8353..77680db1f12 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassIncludesInheritedMembers/input.ts/es5.2.minified/output.js @@ -22,20 +22,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var d2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var d2, Base = function() { "use strict"; var Constructor, protoProps, staticProps; function Base(x) { @@ -70,22 +86,26 @@ var d2, _typeof = function(obj) { } } ], protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; -}(Base), d = new Derived(1); -d.a, d.b(), d.c, d.c = "", Derived.r, Derived.s(), Derived.t, Derived.t = ""; + return Derived1; +}(Base), d = new Derived1(1); +d.a, d.b(), d.c, d.c = "", Derived1.r, Derived1.s(), Derived1.t, Derived1.t = ""; var Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); d2[""], d2[1]; diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.1.normal/output.js index 3ba81ffc92e..22a9c0450f1 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.1.normal/output.js @@ -44,19 +44,45 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = // ok, use assignment compatibility +var Derived1 = // ok, use assignment compatibility /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Base2 = function Base2() { "use strict"; @@ -66,9 +92,10 @@ var Derived2 = // ok, use assignment compatibility /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.2.minified/output.js index 7178777f07c..93de082aa66 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesIndexersWithAssignmentCompatibility/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.1.normal/output.js index 38b6e08d0a5..1ba4e242f5c 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Base2 = function Base2() { "use strict"; @@ -64,9 +90,10 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.2.minified/output.js index 7178777f07c..93de082aa66 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPrivates/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.1.normal/output.js index b2088aadc46..b624bab5a4f 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: ES5 var x; var y; @@ -97,14 +122,15 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(a) { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, x)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(a) { + _classCallCheck(this, Derived1); + return _super.call(this, x); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "b", value: function b(a) { @@ -133,5 +159,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.2.minified/output.js index b232f0dc6d7..a057243cd62 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers/input.ts/es5.2.minified/output.js @@ -54,16 +54,9 @@ var x, y, Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived(a) { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, (call = _getPrototypeOf(Derived).call(this, x)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -72,7 +65,35 @@ var x, y, Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1(a) { + return _classCallCheck(this, Derived1), _super.call(this, x); + } + return _createClass(Derived1, [ { key: "b", value: function(a) { @@ -100,5 +121,5 @@ var x, y, Base = function() { set: function(a) { } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.1.normal/output.js index 247653f8be5..77bd10dfb3a 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: ES5 var x; var y; @@ -97,15 +122,16 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = // Increase visibility of all protected members to public +var Derived1 = // Increase visibility of all protected members to public /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(a) { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, a)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(a) { + _classCallCheck(this, Derived1); + return _super.call(this, a); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "b", value: function b(a) { @@ -134,19 +160,19 @@ var Derived = // Increase visibility of all protected members to public } } ]); - return Derived; + return Derived1; }(Base); -var d = new Derived(y); +var d = new Derived1(y); var r1 = d.a; var r2 = d.b(y); var r3 = d.c; var r3a = d.d; d.c = y; -var r4 = Derived.r; -var r5 = Derived.s(y); -var r6 = Derived.t; -var r6a = Derived.u; -Derived.t = y; +var r4 = Derived1.r; +var r5 = Derived1.s(y); +var r6 = Derived1.t; +var r6a = Derived1.u; +Derived1.t = y; var Base2 = function Base2() { "use strict"; _classCallCheck(this, Base2); @@ -154,9 +180,10 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.2.minified/output.js index 3ae8e7d55e2..a0e48a3aef3 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x, y, d2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x, y, d2, Base = function() { "use strict"; function Base(a) { _classCallCheck(this, Base); @@ -72,12 +88,14 @@ var x, y, d2, _typeof = function(obj) { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived(a) { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, a)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(a) { + return _classCallCheck(this, Derived1), _super.call(this, a); } - return _inherits(Derived, Base), _createClass(Derived, [ + return _createClass(Derived1, [ { key: "b", value: function(a) { @@ -105,17 +123,19 @@ var x, y, d2, _typeof = function(obj) { set: function(a) { } } - ]), Derived; -}(Base), d = new Derived(y); -d.a, d.b(y), d.c, d.d, d.c = y, Derived.r, Derived.s(y), Derived.t, Derived.u, Derived.t = y; + ]), Derived1; +}(Base), d = new Derived1(y); +d.a, d.b(y), d.c, d.d, d.c = y, Derived1.r, Derived1.s(y), Derived1.t, Derived1.u, Derived1.t = y; var Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); d2[""], d2[1]; diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.1.normal/output.js index 3a46194d287..67e5d4aa046 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: ES5 var x; var y; @@ -102,18 +127,20 @@ var Derived1 = // Errors /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1(a) { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).call(this, a)); + return _super.call(this, a); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2(a) { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).call(this, a)); + return _super.call(this, a); } _createClass(Derived2, [ { @@ -127,9 +154,10 @@ var Derived2 = /*#__PURE__*/ function(Base) { var Derived3 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived3, Base); + var _super = _createSuper(Derived3); function Derived3(a) { _classCallCheck(this, Derived3); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived3).call(this, a)); + return _super.call(this, a); } _createClass(Derived3, [ { @@ -144,9 +172,10 @@ var Derived3 = /*#__PURE__*/ function(Base) { var Derived4 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived4, Base); + var _super = _createSuper(Derived4); function Derived4(a) { _classCallCheck(this, Derived4); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived4).call(this, a)); + return _super.call(this, a); } _createClass(Derived4, [ { @@ -160,27 +189,30 @@ var Derived4 = /*#__PURE__*/ function(Base) { var Derived5 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived5, Base); + var _super = _createSuper(Derived5); function Derived5(a) { _classCallCheck(this, Derived5); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived5).call(this, a)); + return _super.call(this, a); } return Derived5; }(Base); var Derived6 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived6, Base); + var _super = _createSuper(Derived6); function Derived6(a) { _classCallCheck(this, Derived6); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived6).call(this, a)); + return _super.call(this, a); } return Derived6; }(Base); var Derived7 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived7, Base); + var _super = _createSuper(Derived7); function Derived7(a) { _classCallCheck(this, Derived7); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived7).call(this, a)); + return _super.call(this, a); } _createClass(Derived7, null, [ { @@ -194,9 +226,10 @@ var Derived7 = /*#__PURE__*/ function(Base) { var Derived8 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived8, Base); + var _super = _createSuper(Derived8); function Derived8(a) { _classCallCheck(this, Derived8); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived8).call(this, a)); + return _super.call(this, a); } _createClass(Derived8, null, [ { @@ -211,9 +244,10 @@ var Derived8 = /*#__PURE__*/ function(Base) { var Derived9 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived9, Base); + var _super = _createSuper(Derived9); function Derived9(a) { _classCallCheck(this, Derived9); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived9).call(this, a)); + return _super.call(this, a); } _createClass(Derived9, null, [ { @@ -227,9 +261,10 @@ var Derived9 = /*#__PURE__*/ function(Base) { var Derived10 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived10, Base); + var _super = _createSuper(Derived10); function Derived10(a) { _classCallCheck(this, Derived10); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived10).call(this, a)); + return _super.call(this, a); } return Derived10; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.2.minified/output.js index 06b657ba8ef..7089d7247c0 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x, Base = function() { "use strict"; function Base(a) { _classCallCheck(this, Base); @@ -74,16 +90,20 @@ var x, _typeof = function(obj) { ]), Base; }(), Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1(a) { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).call(this, a)); + return _classCallCheck(this, Derived1), _super.call(this, a); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2(a) { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).call(this, a)); + return _classCallCheck(this, Derived2), _super.call(this, a); } - return _inherits(Derived2, Base), _createClass(Derived2, [ + return _createClass(Derived2, [ { key: "b", value: function(a) { @@ -92,10 +112,12 @@ var x, _typeof = function(obj) { ]), Derived2; }(Base), Derived3 = function(Base) { "use strict"; + _inherits(Derived3, Base); + var _super = _createSuper(Derived3); function Derived3(a) { - return _classCallCheck(this, Derived3), _possibleConstructorReturn(this, _getPrototypeOf(Derived3).call(this, a)); + return _classCallCheck(this, Derived3), _super.call(this, a); } - return _inherits(Derived3, Base), _createClass(Derived3, [ + return _createClass(Derived3, [ { key: "c", get: function() { @@ -105,10 +127,12 @@ var x, _typeof = function(obj) { ]), Derived3; }(Base), Derived4 = function(Base) { "use strict"; + _inherits(Derived4, Base); + var _super = _createSuper(Derived4); function Derived4(a) { - return _classCallCheck(this, Derived4), _possibleConstructorReturn(this, _getPrototypeOf(Derived4).call(this, a)); + return _classCallCheck(this, Derived4), _super.call(this, a); } - return _inherits(Derived4, Base), _createClass(Derived4, [ + return _createClass(Derived4, [ { key: "c", set: function(v) { @@ -117,22 +141,28 @@ var x, _typeof = function(obj) { ]), Derived4; }(Base), Derived5 = function(Base) { "use strict"; + _inherits(Derived5, Base); + var _super = _createSuper(Derived5); function Derived5(a) { - return _classCallCheck(this, Derived5), _possibleConstructorReturn(this, _getPrototypeOf(Derived5).call(this, a)); + return _classCallCheck(this, Derived5), _super.call(this, a); } - return _inherits(Derived5, Base), Derived5; + return Derived5; }(Base), Derived6 = function(Base) { "use strict"; + _inherits(Derived6, Base); + var _super = _createSuper(Derived6); function Derived6(a) { - return _classCallCheck(this, Derived6), _possibleConstructorReturn(this, _getPrototypeOf(Derived6).call(this, a)); + return _classCallCheck(this, Derived6), _super.call(this, a); } - return _inherits(Derived6, Base), Derived6; + return Derived6; }(Base), Derived7 = function(Base) { "use strict"; + _inherits(Derived7, Base); + var _super = _createSuper(Derived7); function Derived7(a) { - return _classCallCheck(this, Derived7), _possibleConstructorReturn(this, _getPrototypeOf(Derived7).call(this, a)); + return _classCallCheck(this, Derived7), _super.call(this, a); } - return _inherits(Derived7, Base), _createClass(Derived7, null, [ + return _createClass(Derived7, null, [ { key: "s", value: function(a) { @@ -141,10 +171,12 @@ var x, _typeof = function(obj) { ]), Derived7; }(Base), Derived8 = function(Base) { "use strict"; + _inherits(Derived8, Base); + var _super = _createSuper(Derived8); function Derived8(a) { - return _classCallCheck(this, Derived8), _possibleConstructorReturn(this, _getPrototypeOf(Derived8).call(this, a)); + return _classCallCheck(this, Derived8), _super.call(this, a); } - return _inherits(Derived8, Base), _createClass(Derived8, null, [ + return _createClass(Derived8, null, [ { key: "t", get: function() { @@ -154,10 +186,12 @@ var x, _typeof = function(obj) { ]), Derived8; }(Base), Derived9 = function(Base) { "use strict"; + _inherits(Derived9, Base); + var _super = _createSuper(Derived9); function Derived9(a) { - return _classCallCheck(this, Derived9), _possibleConstructorReturn(this, _getPrototypeOf(Derived9).call(this, a)); + return _classCallCheck(this, Derived9), _super.call(this, a); } - return _inherits(Derived9, Base), _createClass(Derived9, null, [ + return _createClass(Derived9, null, [ { key: "t", set: function(v) { @@ -166,8 +200,10 @@ var x, _typeof = function(obj) { ]), Derived9; }(Base), Derived10 = function(Base) { "use strict"; + _inherits(Derived10, Base); + var _super = _createSuper(Derived10); function Derived10(a) { - return _classCallCheck(this, Derived10), _possibleConstructorReturn(this, _getPrototypeOf(Derived10).call(this, a)); + return _classCallCheck(this, Derived10), _super.call(this, a); } - return _inherits(Derived10, Base), Derived10; + return Derived10; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.1.normal/output.js index 4808c13c7b6..574a96f1cc1 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var x; var y; var Base = function Base() { @@ -53,18 +78,20 @@ var Base = function Base() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived1) { "use strict"; _inherits(Derived2, Derived1); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived1); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.2.minified/output.js index 7917c267f8e..e2154a619ca 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Derived1) { "use strict"; + _inherits(Derived2, Derived1); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived1), Derived2; + return Derived2; }(Derived1); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.1.normal/output.js index bbd28799abe..7db4ee67d2c 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var x; var y; var Base = /*#__PURE__*/ function() { @@ -96,14 +121,15 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(a) { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, x)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(a) { + _classCallCheck(this, Derived1); + return _super.call(this, x); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "b", value: function b(a) { @@ -132,19 +158,19 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); -var d = new Derived(y); +var d = new Derived1(y); var r1 = d.a; var r2 = d.b(y); var r3 = d.c; var r3a = d.d; d.c = y; -var r4 = Derived.r; -var r5 = Derived.s(y); -var r6 = Derived.t; -var r6a = Derived.u; -Derived.t = y; +var r4 = Derived1.r; +var r5 = Derived1.s(y); +var r6 = Derived1.t; +var r6a = Derived1.u; +Derived1.t = y; var Base2 = function Base2() { "use strict"; _classCallCheck(this, Base2); @@ -152,9 +178,10 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.2.minified/output.js index ef6864ae75e..661af85a605 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x, y, d2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x, y, d2, Base = function() { "use strict"; function Base(a) { _classCallCheck(this, Base); @@ -72,12 +88,14 @@ var x, y, d2, _typeof = function(obj) { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived(a) { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, x)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(a) { + return _classCallCheck(this, Derived1), _super.call(this, x); } - return _inherits(Derived, Base), _createClass(Derived, [ + return _createClass(Derived1, [ { key: "b", value: function(a) { @@ -105,17 +123,19 @@ var x, y, d2, _typeof = function(obj) { set: function(a) { } } - ]), Derived; -}(Base), d = new Derived(y); -d.a, d.b(y), d.c, d.d, d.c = y, Derived.r, Derived.s(y), Derived.t, Derived.u, Derived.t = y; + ]), Derived1; +}(Base), d = new Derived1(y); +d.a, d.b(y), d.c, d.d, d.c = y, Derived1.r, Derived1.s(y), Derived1.t, Derived1.u, Derived1.t = y; var Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); d2[""], d2[1]; diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.1.normal/output.js index 38b6e08d0a5..1ba4e242f5c 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Base2 = function Base2() { "use strict"; @@ -64,9 +90,10 @@ var Base2 = function Base2() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.2.minified/output.js index 7178777f07c..93de082aa66 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.1.normal/output.js index f0ff6dff823..deb09d58ff9 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // subclassing is not transitive when you can remove required parameters and add optional parameters /*#__PURE__*/ function() { "use strict"; @@ -76,9 +101,10 @@ var C = // subclassing is not transitive when you can remove required parameters var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -92,9 +118,10 @@ var D = /*#__PURE__*/ function(C) { var E = /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.2.minified/output.js index df1bc8fd7b6..0f847f9ddd1 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -52,10 +68,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo", value: function() { @@ -64,10 +82,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "foo", value: function(x) { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.1.normal/output.js index cf758021fba..92187ab6903 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // subclassing is not transitive when you can remove required parameters and add optional parameters /*#__PURE__*/ function() { "use strict"; @@ -76,9 +101,10 @@ var C = // subclassing is not transitive when you can remove required parameters var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -92,9 +118,10 @@ var D = /*#__PURE__*/ function(C) { var E = /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.2.minified/output.js index ff457f16ce6..b8edf59fe85 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity2/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -52,10 +68,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo", value: function(x) { @@ -64,10 +82,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "foo", value: function(x, y) { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.1.normal/output.js index d18fc893d06..55010e67b13 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // subclassing is not transitive when you can remove required parameters and add optional parameters /*#__PURE__*/ function() { "use strict"; @@ -76,9 +101,10 @@ var C = // subclassing is not transitive when you can remove required parameters var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -92,9 +118,10 @@ var D = /*#__PURE__*/ function(C) { var E = /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.2.minified/output.js index a7bbfddba22..a18308a715a 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity3/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -52,10 +68,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo", value: function(x) { @@ -64,10 +82,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "foo", value: function(x, y) { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.1.normal/output.js index fff04f23343..c8dad6b00a1 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // subclassing is not transitive when you can remove required parameters and add optional parameters on protected members /*#__PURE__*/ function() { "use strict"; @@ -76,9 +101,10 @@ var C = // subclassing is not transitive when you can remove required parameters var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -92,9 +118,10 @@ var D = /*#__PURE__*/ function(C) { var E = /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.2.minified/output.js index df1bc8fd7b6..0f847f9ddd1 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassTransitivity4/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -52,10 +68,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo", value: function() { @@ -64,10 +82,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "foo", value: function(x) { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.1.normal/output.js index b2f9faf16b8..1d9b19b44aa 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C() { @@ -95,9 +120,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -132,9 +158,10 @@ var E = // if D is a valid class definition than E is now not safe tranisitively /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.2.minified/output.js index 317e6eea828..60a21d2a069 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithAny/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -72,10 +88,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "X", get: function() { @@ -104,10 +122,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "X", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.1.normal/output.js index c5d4cf0ee8c..c8760a97f7a 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: ES5 /*#__PURE__*/ function() { "use strict"; @@ -82,15 +107,16 @@ var Base = // @target: ES5 ]); return Base; }(); -var Derived = // error, not a subtype +var Derived1 = // error, not a subtype /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "fn", value: function fn() { @@ -106,5 +132,5 @@ var Derived = // error, not a subtype } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.2.minified/output.js index ac1c841d7fa..3cfab04b962 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance/input.ts/es5.2.minified/output.js @@ -41,16 +41,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -59,7 +52,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "fn", value: function() { @@ -74,5 +95,5 @@ var Base = function() { set: function(v) { } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.1.normal/output.js index 4747fe1fda0..1281f5f3d8b 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -81,15 +106,16 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = // error, not a subtype +var Derived1 = // error, not a subtype /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "fn", value: function fn() { @@ -105,13 +131,13 @@ var Derived = // error, not a subtype } } ]); - return Derived; + return Derived1; }(Base); var r = Base.x; // ok -var r2 = Derived.x; // error +var r2 = Derived1.x; // error var r3 = Base.fn(); // ok -var r4 = Derived.fn(); // error +var r4 = Derived1.fn(); // error var r5 = Base.a; // ok Base.a = 2; // ok -var r6 = Derived.a; // error -Derived.a = 2; // error +var r6 = Derived1.a; // error +Derived1.a = 2; // error diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.2.minified/output.js index 1414af801df..b8b8dfb973a 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingPublicInstance/input.ts/es5.2.minified/output.js @@ -41,16 +41,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -59,7 +52,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "fn", value: function() { @@ -74,6 +95,6 @@ var Base = function() { set: function(v) { } } - ]), Derived; + ]), Derived1; }(Base); -Base.x, Derived.x, Base.fn(), Derived.fn(), Base.a, Base.a = 2, Derived.a, Derived.a = 2; +Base.x, Derived1.x, Base.fn(), Derived1.fn(), Base.a, Base.a = 2, Derived1.a, Derived1.a = 2; diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.1.normal/output.js index 7a9549ee7c3..e4f596236df 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: ES5 /*#__PURE__*/ function() { "use strict"; @@ -82,15 +107,16 @@ var Base = // @target: ES5 ]); return Base; }(); -var Derived = // should be error +var Derived1 = // should be error /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, null, [ + _createClass(Derived1, null, [ { key: "fn", value: function fn() { @@ -106,5 +132,5 @@ var Derived = // should be error } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.2.minified/output.js index 69da3ee9160..2ef7807949a 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic/input.ts/es5.2.minified/output.js @@ -41,16 +41,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -59,7 +52,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, null, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, null, [ { key: "fn", value: function() { @@ -74,5 +95,5 @@ var Base = function() { set: function(v) { } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.1.normal/output.js index 37fb1412d58..c753b1c8a50 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -81,16 +106,17 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = // BUG 847404 +var Derived1 = // BUG 847404 // should be error /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, null, [ + _createClass(Derived1, null, [ { key: "fn", value: function fn() { @@ -106,13 +132,13 @@ var Derived = // BUG 847404 } } ]); - return Derived; + return Derived1; }(Base); var r = Base.x; // ok -var r2 = Derived.x; // error +var r2 = Derived1.x; // error var r3 = Base.fn(); // ok -var r4 = Derived.fn(); // error +var r4 = Derived1.fn(); // error var r5 = Base.a; // ok Base.a = 2; // ok -var r6 = Derived.a; // error -Derived.a = 2; // error +var r6 = Derived1.a; // error +Derived1.a = 2; // error diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.2.minified/output.js index af39c846395..2f44eaa70f7 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic/input.ts/es5.2.minified/output.js @@ -41,16 +41,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -59,7 +52,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, null, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, null, [ { key: "fn", value: function() { @@ -74,6 +95,6 @@ var Base = function() { set: function(v) { } } - ]), Derived; + ]), Derived1; }(Base); -Base.x, Derived.x, Base.fn(), Derived.fn(), Base.a, Base.a = 2, Derived.a, Derived.a = 2; +Base.x, Derived1.x, Base.fn(), Derived1.fn(), Base.a, Base.a = 2, Derived1.a, Derived1.a = 2; diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.1.normal/output.js index 51b7c48eb58..913b2259468 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C() { @@ -82,9 +107,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -119,9 +145,10 @@ var E = // if D is a valid class definition than E is now not safe tranisitively /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.2.minified/output.js index 095e0431d3d..51a4ccf25d8 100644 --- a/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var e, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var e, C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -59,10 +75,12 @@ var e, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "X", get: function() { @@ -91,10 +109,12 @@ var e, _typeof = function(obj) { ]), D; }(C), E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, D), _createClass(E, [ + return _createClass(E, [ { key: "X", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.1.normal/output.js index 7273c0de57e..98f26c6fc38 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -51,11 +76,12 @@ var B = function B() { var A = /*#__PURE__*/ function(B) { "use strict"; _inherits(A, B); + var _super = _createSuper(A); function A() { _classCallCheck(this, A); var _this; void 0; // Error: 'super' call must come first - _this = _possibleConstructorReturn(this, _getPrototypeOf(A).call(this)); + _this = _super.call(this); _x.set(_assertThisInitialized(_this), { writable: true, value: void 0 diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.2.minified/output.js index c56de23beb7..298191c8c26 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuper/input.ts/es5.2.minified/output.js @@ -20,14 +20,7 @@ var B1 = function() { _classCallCheck(this, B1); }, A = function(B) { "use strict"; - function A() { - var _this, self, call, obj; - return _classCallCheck(this, A), self = this, _this = (call = _getPrototypeOf(A).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self), _x.set(_assertThisInitialized(_this), { - writable: !0, - value: void 0 - }), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,5 +29,34 @@ var B1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(A, B), A; + }(A, B); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(A); + function A() { + var _this; + return _classCallCheck(this, A), _this = _super.call(this), _x.set(_assertThisInitialized(_this), { + writable: !0, + value: void 0 + }), _this; + } + return A; }(B1), _x = new WeakMap(); diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.1.normal/output.js index 7273c0de57e..98f26c6fc38 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -51,11 +76,12 @@ var B = function B() { var A = /*#__PURE__*/ function(B) { "use strict"; _inherits(A, B); + var _super = _createSuper(A); function A() { _classCallCheck(this, A); var _this; void 0; // Error: 'super' call must come first - _this = _possibleConstructorReturn(this, _getPrototypeOf(A).call(this)); + _this = _super.call(this); _x.set(_assertThisInitialized(_this), { writable: true, value: void 0 diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.2.minified/output.js index c56de23beb7..298191c8c26 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields/input.ts/es5.2.minified/output.js @@ -20,14 +20,7 @@ var B1 = function() { _classCallCheck(this, B1); }, A = function(B) { "use strict"; - function A() { - var _this, self, call, obj; - return _classCallCheck(this, A), self = this, _this = (call = _getPrototypeOf(A).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self), _x.set(_assertThisInitialized(_this), { - writable: !0, - value: void 0 - }), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,5 +29,34 @@ var B1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(A, B), A; + }(A, B); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(A); + function A() { + var _this; + return _classCallCheck(this, A), _this = _super.call(this), _x.set(_assertThisInitialized(_this), { + writable: !0, + value: void 0 + }), _this; + } + return A; }(B1), _x = new WeakMap(); diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.1.normal/output.js index 77bcb52ed95..55f6201f114 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.1.normal/output.js @@ -55,6 +55,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -68,10 +93,11 @@ var _foo = new WeakMap(); var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this)); + _this = _super.call(this); _foo1.set(_assertThisInitialized(_this), { writable: true, value: void 0 diff --git a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.2.minified/output.js index ab08c33bb1f..992f3ea7220 100644 --- a/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/members/privateNames/privateNamesAndFields/input.ts/es5.2.minified/output.js @@ -29,14 +29,7 @@ var A1 = function() { }), _classPrivateFieldSet(this, _foo, 3); }, _foo = new WeakMap(), B = function(A) { "use strict"; - function B() { - var _this, self, call, obj; - return _classCallCheck(this, B), self = this, _this = (call = _getPrototypeOf(B).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self), _foo1.set(_assertThisInitialized(_this), { - writable: !0, - value: void 0 - }), _classPrivateFieldSet(_assertThisInitialized(_this), _foo1, "some string"), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -45,5 +38,34 @@ var A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(B); + function B() { + var _this; + return _classCallCheck(this, B), _this = _super.call(this), _foo1.set(_assertThisInitialized(_this), { + writable: !0, + value: void 0 + }), _classPrivateFieldSet(_assertThisInitialized(_this), _foo1, "some string"), _this; + } + return B; }(A1), _foo1 = new WeakMap(); diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.1.normal/output.js index 33d0ab9808d..4f10eeabdc8 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.1.normal/output.js @@ -58,14 +58,40 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function Mixin(baseClass1) { var MixinClass = // error expected: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. /*#__PURE__*/ function(baseClass) { "use strict"; _inherits(MixinClass, baseClass); + var _super = _createSuper(MixinClass); function MixinClass() { _classCallCheck(this, MixinClass); - return _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MixinClass, [ { @@ -87,9 +113,10 @@ var DerivedFromAbstract = // error expected: Non-abstract class 'DerivedFromAbst /*#__PURE__*/ function(MixedBase) { "use strict"; _inherits(DerivedFromAbstract, MixedBase); + var _super = _createSuper(DerivedFromAbstract); function DerivedFromAbstract() { _classCallCheck(this, DerivedFromAbstract); - return _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract).apply(this, arguments)); + return _super.apply(this, arguments); } return DerivedFromAbstract; }(MixedBase1); diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.2.minified/output.js index f6df71411f4..b6da3e5ace2 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses.2/input.ts/es5.2.minified/output.js @@ -22,30 +22,47 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, AbstractBase = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var AbstractBase = function() { "use strict"; _classCallCheck(this, AbstractBase); }, MixedBase1 = function(baseClass1) { var MixinClass = function(baseClass) { "use strict"; - var Constructor, protoProps, staticProps; + _inherits(MixinClass, baseClass); + var Constructor, protoProps, staticProps, _super = _createSuper(MixinClass); function MixinClass() { - return _classCallCheck(this, MixinClass), _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _classCallCheck(this, MixinClass), _super.apply(this, arguments); } - return _inherits(MixinClass, baseClass), protoProps = [ + return protoProps = [ { key: "mixinMethod", value: function() { @@ -56,9 +73,11 @@ var _typeof = function(obj) { return MixinClass; }(AbstractBase), DerivedFromAbstract = function(MixedBase) { "use strict"; + _inherits(DerivedFromAbstract, MixedBase); + var _super = _createSuper(DerivedFromAbstract); function DerivedFromAbstract() { - return _classCallCheck(this, DerivedFromAbstract), _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract).apply(this, arguments)); + return _classCallCheck(this, DerivedFromAbstract), _super.apply(this, arguments); } - return _inherits(DerivedFromAbstract, MixedBase), DerivedFromAbstract; + return DerivedFromAbstract; }(MixedBase1); new MixedBase1(); diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.1.normal/output.js index e95022dd84d..a9b8ae72873 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.1.normal/output.js @@ -58,13 +58,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function Mixin(baseClass1) { var MixinClass = /*#__PURE__*/ function(baseClass) { "use strict"; _inherits(MixinClass, baseClass); + var _super = _createSuper(MixinClass); function MixinClass() { _classCallCheck(this, MixinClass); - return _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MixinClass, [ { @@ -98,9 +124,10 @@ var AbstractBase = function AbstractBase() { var DerivedFromConcrete = /*#__PURE__*/ function(_super) { "use strict"; _inherits(DerivedFromConcrete, _super); + var _super1 = _createSuper(DerivedFromConcrete); function DerivedFromConcrete() { _classCallCheck(this, DerivedFromConcrete); - return _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromConcrete).apply(this, arguments)); + return _super1.apply(this, arguments); } return DerivedFromConcrete; }(Mixin(ConcreteBase)); @@ -110,9 +137,10 @@ wasConcrete.mixinMethod(); var DerivedFromAbstract = /*#__PURE__*/ function(_super) { "use strict"; _inherits(DerivedFromAbstract, _super); + var _super2 = _createSuper(DerivedFromAbstract); function DerivedFromAbstract() { _classCallCheck(this, DerivedFromAbstract); - return _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract).apply(this, arguments)); + return _super2.apply(this, arguments); } _createClass(DerivedFromAbstract, [ { diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.2.minified/output.js index f42c7ad957b..a7b85ebb71a 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClasses/input.ts/es5.2.minified/output.js @@ -25,27 +25,44 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function Mixin(baseClass1) { var MixinClass = function(baseClass) { "use strict"; + _inherits(MixinClass, baseClass); + var _super = _createSuper(MixinClass); function MixinClass() { - return _classCallCheck(this, MixinClass), _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _classCallCheck(this, MixinClass), _super.apply(this, arguments); } - return _inherits(MixinClass, baseClass), _createClass(MixinClass, [ + return _createClass(MixinClass, [ { key: "mixinMethod", value: function() { @@ -72,18 +89,22 @@ var ConcreteBase = function() { _classCallCheck(this, AbstractBase); }, DerivedFromConcrete = function(_super) { "use strict"; + _inherits(DerivedFromConcrete, _super); + var _super1 = _createSuper(DerivedFromConcrete); function DerivedFromConcrete() { - return _classCallCheck(this, DerivedFromConcrete), _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromConcrete).apply(this, arguments)); + return _classCallCheck(this, DerivedFromConcrete), _super1.apply(this, arguments); } - return _inherits(DerivedFromConcrete, _super), DerivedFromConcrete; + return DerivedFromConcrete; }(Mixin(ConcreteBase)), wasConcrete = new DerivedFromConcrete(); wasConcrete.baseMethod(), wasConcrete.mixinMethod(); var DerivedFromAbstract = function(_super) { "use strict"; + _inherits(DerivedFromAbstract, _super); + var _super2 = _createSuper(DerivedFromAbstract); function DerivedFromAbstract() { - return _classCallCheck(this, DerivedFromAbstract), _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract).apply(this, arguments)); + return _classCallCheck(this, DerivedFromAbstract), _super2.apply(this, arguments); } - return _inherits(DerivedFromAbstract, _super), _createClass(DerivedFromAbstract, [ + return _createClass(DerivedFromAbstract, [ { key: "abstractBaseMethod", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.1.normal/output.js index ac7e2447c64..bc8546a1afc 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var AbstractBase = function AbstractBase() { "use strict"; _classCallCheck(this, AbstractBase); @@ -68,9 +93,10 @@ function Mixin2(baseClass1) { /*#__PURE__*/ function(baseClass) { "use strict"; _inherits(MixinClass, baseClass); + var _super = _createSuper(MixinClass); function MixinClass() { _classCallCheck(this, MixinClass); - return _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MixinClass, [ { @@ -92,9 +118,10 @@ function Mixin2(baseClass1) { var DerivedFromAbstract2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(DerivedFromAbstract2, _super); + var _super1 = _createSuper(DerivedFromAbstract2); function DerivedFromAbstract2() { _classCallCheck(this, DerivedFromAbstract2); - return _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract2).apply(this, arguments)); + return _super1.apply(this, arguments); } _createClass(DerivedFromAbstract2, [ { diff --git a/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.2.minified/output.js index 30113b546d3..d345b0c0548 100644 --- a/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/mixinAbstractClassesReturnTypeInference/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, AbstractBase = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var AbstractBase = function() { "use strict"; _classCallCheck(this, AbstractBase); }, DerivedFromAbstract2 = function(_super) { "use strict"; + _inherits(DerivedFromAbstract2, _super); + var _super1 = _createSuper(DerivedFromAbstract2); function DerivedFromAbstract2() { - return _classCallCheck(this, DerivedFromAbstract2), _possibleConstructorReturn(this, _getPrototypeOf(DerivedFromAbstract2).apply(this, arguments)); + return _classCallCheck(this, DerivedFromAbstract2), _super1.apply(this, arguments); } - return _inherits(DerivedFromAbstract2, _super), _createClass(DerivedFromAbstract2, [ + return _createClass(DerivedFromAbstract2, [ { key: "abstractBaseMethod", value: function() { @@ -56,10 +74,12 @@ var _typeof = function(obj) { }(function(baseClass1) { var MixinClass = function(baseClass) { "use strict"; + _inherits(MixinClass, baseClass); + var _super = _createSuper(MixinClass); function MixinClass() { - return _classCallCheck(this, MixinClass), _possibleConstructorReturn(this, _getPrototypeOf(MixinClass).apply(this, arguments)); + return _classCallCheck(this, MixinClass), _super.apply(this, arguments); } - return _inherits(MixinClass, baseClass), _createClass(MixinClass, [ + return _createClass(MixinClass, [ { key: "mixinMethod", value: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.1.normal/output.js index 984b3603d37..a88c237790f 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: es2015,esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -78,10 +103,11 @@ var A = // @target: es2015,esnext var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 'B.x'; return _this; } @@ -90,9 +116,10 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.2.minified/output.js index effda422289..d5921c22bcc 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/abstractProperty/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -53,17 +69,21 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { var _this; - return _classCallCheck(this, B), _this = _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)), _this.x = "B.x", _this; + return _classCallCheck(this, B), _this = _super.apply(this, arguments), _this.x = "B.x", _this; } - return _inherits(B, A), B; + return B; }(A), C = function(A) { "use strict"; + _inherits(C, A); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, A), _createClass(C, [ + return _createClass(C, [ { key: "x", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.1.normal/output.js index 21222587dd3..ce61411060d 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -77,9 +102,10 @@ var A = // @target: esnext var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.2.minified/output.js index 1cd7c6145c1..8c7a4faef57 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideMethod/input.ts/es5.2.minified/output.js @@ -34,14 +34,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -50,7 +43,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "m", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.1.normal/output.js index 7216e328238..896627e1558 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -68,9 +93,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -90,10 +116,11 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._secret = 11; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.2.minified/output.js index 2e0769ff4b3..69ddb93bb66 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1), this.p = "yep"; }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "p", get: function() { @@ -59,11 +77,13 @@ var _typeof = function(obj) { _classCallCheck(this, C1), this.p = 101; }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this._secret = 11, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this._secret = 11, _this; } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "p", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.1.normal/output.js index bc0735809cf..245432c7f7b 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -65,14 +90,15 @@ var Base = function Base() { // @useDefineForClassFields: true this.x = 1; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "x", get: function get() { @@ -84,7 +110,7 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); -var obj1 = new Derived(); // nothing printed +var obj1 = new Derived1(); // nothing printed console.log(obj1.x); // 1 diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.2.minified/output.js index 9c0979fd83d..3860b1d216e 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty2/input.ts/es5.2.minified/output.js @@ -20,17 +20,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1), this.x = 1; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - var Constructor, protoProps, staticProps; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Constructor = Derived, protoProps = [ + }(Derived1, Base); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Constructor = Derived1, protoProps = [ { key: "x", get: function() { @@ -49,6 +69,6 @@ var Base1 = function() { console.log("x was set to ".concat(value)); } } - ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Derived; -}(Base1), obj1 = new Derived(); + ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Derived1; +}(Base1), obj1 = new Derived1(); console.log(obj1.x); // 1 diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.1.normal/output.js index b0415ffa1b7..caca4a2d060 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.1.normal/output.js @@ -58,13 +58,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Lion = /*#__PURE__*/ function(Animal) { "use strict"; _inherits(Lion, Animal); + var _super = _createSuper(Lion); function Lion() { _classCallCheck(this, Lion); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Lion).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._sound = 'grrr'; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.2.minified/output.js index fdeb62e8071..e2a3f98820f 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty3/input.ts/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var Lion = function(Animal) { "use strict"; - var Constructor, protoProps, staticProps; - function Lion() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Lion), self = this, call = _getPrototypeOf(Lion).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._sound = "grrr", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,38 @@ var Lion = function(Animal) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Lion, Animal), Constructor = Lion, protoProps = [ + }(Lion, Animal); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Lion); + function Lion() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Lion), _this = _super.apply(this, arguments), _this._sound = "grrr", _this; + } + return Constructor = Lion, protoProps = [ { key: "sound", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.1.normal/output.js index 9098d21ea2f..f70ff7496fc 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.1.normal/output.js @@ -58,13 +58,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Lion = /*#__PURE__*/ function(Animal) { "use strict"; _inherits(Lion, Animal); + var _super = _createSuper(Lion); function Lion() { _classCallCheck(this, Lion); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Lion).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._sound = 'roar'; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.2.minified/output.js index a1a2931180c..507e9062493 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty4/input.ts/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var Lion = function(Animal) { "use strict"; - var Constructor, protoProps, staticProps; - function Lion() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Lion), self = this, call = _getPrototypeOf(Lion).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._sound = "roar", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,38 @@ var Lion = function(Animal) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Lion, Animal), Constructor = Lion, protoProps = [ + }(Lion, Animal); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Lion); + function Lion() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Lion), _this = _super.apply(this, arguments), _this._sound = "roar", _this; + } + return Constructor = Lion, protoProps = [ { key: "sound", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.1.normal/output.js index 7e27b67055d..0767196f063 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -65,9 +90,10 @@ var B = function B() { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.2.minified/output.js index fbe87d9b9d9..d1ffa1dab67 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty5/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var B1 = function() { _classCallCheck(this, B1); }, C = function(B) { "use strict"; - var Constructor, protoProps, staticProps; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var B1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, B), Constructor = C, protoProps = [ + }(C, B); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return Constructor = C, protoProps = [ { key: "p", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.1.normal/output.js index 18c1bff9f00..523997cffa9 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -68,9 +93,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -90,10 +116,11 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._secret = 11; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.2.minified/output.js index 2e0769ff4b3..69ddb93bb66 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty6/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1), this.p = "yep"; }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "p", get: function() { @@ -59,11 +77,13 @@ var _typeof = function(obj) { _classCallCheck(this, C1), this.p = 101; }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this._secret = 11, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this._secret = 11, _this; } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "p", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.1.normal/output.js index a91dc31f3dd..e3da0ae93bb 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -68,9 +93,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.2.minified/output.js index ea18d8a38b8..78e55d8545f 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/accessorsOverrideProperty7/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var A1 = function() { _classCallCheck(this, A1), this.p = "yep"; }, B = function(A) { "use strict"; - var Constructor, protoProps, staticProps; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), protoProps = [ + }(B, A); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return protoProps = [ { key: "p", get: function() { diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.1.normal/output.js index 822652c3a7c..b36235635a3 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // @useDefineForClassFields: true // @target: esnext /*#__PURE__*/ function() { @@ -105,10 +130,11 @@ var C = // @useDefineForClassFields: true var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.quill // ok = _this.foo; return _this; @@ -131,10 +157,11 @@ var F1 = function F1() { _classCallCheck(this, F1); this.Inner = /*#__PURE__*/ (function(F) { _inherits(_class, F); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.p2 = _this.p1; return _this; } @@ -148,10 +175,11 @@ var G1 = function G1(p1) { this.p1 = p1; this.Inner = /*#__PURE__*/ (function(G) { _inherits(_class, G); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.p2 = _this.p1; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.2.minified/output.js index c8601a4c602..aa50e192441 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext/input.ts/es5.2.minified/output.js @@ -22,20 +22,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function() { "use strict"; var Constructor, protoProps, staticProps; function C(foo) { @@ -58,11 +74,13 @@ var _typeof = function(obj) { ], _defineProperties((Constructor = C).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this.quill = _this.foo, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this.quill = _this.foo, _this; } - return _inherits(D, C), D; + return D; }(C), E = function(foo2) { "use strict"; var _this = this; @@ -72,19 +90,23 @@ var _typeof = function(obj) { }, F1 = function() { "use strict"; _classCallCheck(this, F1), this.Inner = (function(F) { + _inherits(_class, F); + var _super = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.p2 = _this.p1, _this; + return _classCallCheck(this, _class), _this = _super.apply(this, arguments), _this.p2 = _this.p1, _this; } - return _inherits(_class, F), _class; + return _class; })(F1), this.p1 = 0; }, G1 = function(p1) { "use strict"; _classCallCheck(this, G1), this.p1 = p1, this.Inner = (function(G) { + _inherits(_class, G); + var _super = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.p2 = _this.p1, _this; + return _classCallCheck(this, _class), _this = _super.apply(this, arguments), _this.p2 = _this.p1, _this; } - return _inherits(_class, G), _class; + return _class; })(G1); }; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.1.normal/output.js index 760b7fe9c2a..6e573c83e7a 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _key, _key1; // @target: es5, esnext // @useDefineForClassFields: true @@ -90,10 +115,11 @@ var B = function B() { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C(ka) { _classCallCheck(this, C); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)); + _this = _super.call(this); _this.ka = ka; _this.z = _this.ka; _this.ki = _this.ka; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.2.minified/output.js index 61850550232..af89cd20f40 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/defineProperty/input.ts/es5.2.minified/output.js @@ -37,14 +37,7 @@ var B1 = function() { _classCallCheck(this, B1); }, C = function(B) { "use strict"; - function C(ka) { - var _this, self, call, obj; - return _classCallCheck(this, C), (_this = (self = this, (call = _getPrototypeOf(C).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).ka = ka, _this.z = _this.ka, _this.ki = _this.ka, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -53,5 +46,34 @@ var B1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, B), C; + }(C, B); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C(ka) { + var _this; + return _classCallCheck(this, C), (_this = _super.call(this)).ka = ka, _this.z = _this.ka, _this.ki = _this.ka, _this; + } + return C; }(B1); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.1.normal/output.js index e76285e9f96..77b93e8475d 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -96,14 +121,15 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "foo", value: function foo(x) { @@ -113,10 +139,10 @@ var Derived = /*#__PURE__*/ function(Base) { { key: "bar", value: function bar() { - var r = _get(_getPrototypeOf(Derived.prototype), "foo", this).call(this, { + var r = _get(_getPrototypeOf(Derived1.prototype), "foo", this).call(this, { a: 1 }); // { a: number } - var r2 = _get(_getPrototypeOf(Derived.prototype), "foo", this).call(this, { + var r2 = _get(_getPrototypeOf(Derived1.prototype), "foo", this).call(this, { a: 1, b: 2 }); // { a: number } @@ -127,5 +153,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.2.minified/output.js index fea5eeecae2..46b758723c8 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess/input.ts/es5.2.minified/output.js @@ -46,16 +46,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "foo", value: function(x) { @@ -74,9 +95,9 @@ var Base = function() { { key: "bar", value: function() { - _get(_getPrototypeOf(Derived.prototype), "foo", this).call(this, { + _get(_getPrototypeOf(Derived1.prototype), "foo", this).call(this, { a: 1 - }), _get(_getPrototypeOf(Derived.prototype), "foo", this).call(this, { + }), _get(_getPrototypeOf(Derived1.prototype), "foo", this).call(this, { a: 1, b: 2 }), this.foo({ @@ -85,5 +106,5 @@ var Base = function() { }); } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.1.normal/output.js index fb6086b8654..b668c955ec1 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = /*#__PURE__*/ function() { "use strict"; function Base() { @@ -80,14 +105,15 @@ var Base = /*#__PURE__*/ function() { ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "foo", value: function foo() { @@ -95,7 +121,7 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); -var d = Derived.create(); +var d = Derived1.create(); d.foo(); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.2.minified/output.js index fcb530fccda..e3191f2e1af 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/memberFunctionDeclarations/staticFactory1/input.ts/es5.2.minified/output.js @@ -40,16 +40,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -58,13 +51,41 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "foo", value: function() { return 2; } } - ]), Derived; + ]), Derived1; }(Base); -Derived.create().foo(); +Derived1.create().foo(); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.1.normal/output.js index 32abf357f34..b44d19cba9a 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.1.normal/output.js @@ -58,12 +58,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Sizz = /*#__PURE__*/ function(Mup) { "use strict"; _inherits(Sizz, Mup); + var _super = _createSuper(Sizz); function Sizz() { _classCallCheck(this, Sizz); - return _possibleConstructorReturn(this, _getPrototypeOf(Sizz).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Sizz, [ { @@ -79,10 +105,11 @@ var Sizz = /*#__PURE__*/ function(Mup) { var Kasizz = /*#__PURE__*/ function(Mup) { "use strict"; _inherits(Kasizz, Mup); + var _super = _createSuper(Kasizz); function Kasizz() { _classCallCheck(this, Kasizz); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Kasizz).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.size = -1; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.2.minified/output.js index 324b4f4adfe..b26e1f50518 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/overrideInterfaceProperty/input.ts/es5.2.minified/output.js @@ -22,26 +22,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Sizz = function(Mup) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Sizz = function(Mup) { "use strict"; - var Constructor, protoProps, staticProps; + _inherits(Sizz, Mup); + var Constructor, protoProps, staticProps, _super = _createSuper(Sizz); function Sizz() { - return _classCallCheck(this, Sizz), _possibleConstructorReturn(this, _getPrototypeOf(Sizz).apply(this, arguments)); + return _classCallCheck(this, Sizz), _super.apply(this, arguments); } - return _inherits(Sizz, Mup), protoProps = [ + return protoProps = [ { key: "size", get: function() { @@ -51,9 +68,11 @@ var _typeof = function(obj) { ], _defineProperties((Constructor = Sizz).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Sizz; }(Mup), Kasizz = function(Mup) { "use strict"; + _inherits(Kasizz, Mup); + var _super = _createSuper(Kasizz); function Kasizz() { var _this; - return _classCallCheck(this, Kasizz), _this = _possibleConstructorReturn(this, _getPrototypeOf(Kasizz).apply(this, arguments)), _this.size = -1, _this; + return _classCallCheck(this, Kasizz), _this = _super.apply(this, arguments), _this.size = -1, _this; } - return _inherits(Kasizz, Mup), Kasizz; + return Kasizz; }(Mup); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.1.normal/output.js index 65dcb225127..3b6cf93f9e1 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: es2015 // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -78,10 +103,11 @@ var A = // @target: es2015 var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.p // error = 'yep'; return _this; @@ -110,10 +136,11 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.p // error = 101; return _this; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.2.minified/output.js index 2c453618fff..ddc78b262ae 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -53,11 +69,13 @@ var _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { var _this; - return _classCallCheck(this, B), _this = _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)), _this.p = "yep", _this; + return _classCallCheck(this, B), _this = _super.apply(this, arguments), _this.p = "yep", _this; } - return _inherits(B, A), B; + return B; }(A), C = function() { "use strict"; function C() { @@ -76,9 +94,11 @@ var _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { var _this; - return _classCallCheck(this, D), _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)), _this.p = 101, _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this.p = 101, _this; } - return _inherits(D, C), D; + return D; }(C); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.1.normal/output.js index b8542142107..66347c4f837 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -78,17 +103,18 @@ var Base = // @target: esnext ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.x = 1; return _this; } - return Derived; + return Derived1; }(Base); -var obj1 = new Derived(); // prints 'x was set to 1' +var obj1 = new Derived1(); // prints 'x was set to 1' console.log(obj1.x); // 2 diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.2.minified/output.js index 6337dc3998f..83fb253ccbe 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors2/input.ts/es5.2.minified/output.js @@ -34,16 +34,9 @@ var Base = function() { } } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var _this, self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).x = 1, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -52,6 +45,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; -}(Base), obj1 = new Derived(); + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + var _this; + return _classCallCheck(this, Derived1), _this = _super.apply(this, arguments), _this.x = 1, _this; + } + return Derived1; +}(Base), obj1 = new Derived1(); console.log(obj1.x); // 2 diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.1.normal/output.js index 638d5c1d6a0..917bb392cf5 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Animal = // @target: esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -91,10 +116,11 @@ a.makeSound() // 'rustling noise in the bushes' var Lion = /*#__PURE__*/ function(Animal) { "use strict"; _inherits(Lion, Animal); + var _super = _createSuper(Lion); function Lion() { _classCallCheck(this, Lion); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Lion).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.sound // error here = 'RAWR!'; return _this; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.2.minified/output.js index 2c31642d297..4ce19f53911 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors3/input.ts/es5.2.minified/output.js @@ -44,14 +44,7 @@ var Animal = function() { (new Animal).makeSound(); var Lion = function(Animal) { "use strict"; - function Lion() { - var _this, self, call, obj; - return _classCallCheck(this, Lion), self = this, call = _getPrototypeOf(Lion).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).sound = "RAWR!", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -60,7 +53,36 @@ var Lion = function(Animal) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Lion, Animal), Lion; + }(Lion, Animal); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Lion); + function Lion() { + var _this; + return _classCallCheck(this, Lion), _this = _super.apply(this, arguments), _this.sound = "RAWR!", _this; + } + return Lion; }(Animal); (new Lion).makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" ; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.1.normal/output.js index 43f84aced43..2288c3a31b4 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.1.normal/output.js @@ -44,13 +44,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Lion = /*#__PURE__*/ function(Animal) { "use strict"; _inherits(Lion, Animal); + var _super = _createSuper(Lion); function Lion() { _classCallCheck(this, Lion); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Lion).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.sound // error here = 'RAWR!'; return _this; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.2.minified/output.js index 06c8ddb0744..534a0e8d512 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors4/input.ts/es5.2.minified/output.js @@ -10,16 +10,7 @@ function _setPrototypeOf(o, p) { } var Lion = function(Animal) { "use strict"; - function Lion() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Lion), self = this, call = _getPrototypeOf(Lion).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).sound = "RAWR!", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -28,5 +19,36 @@ var Lion = function(Animal) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Lion, Animal), Lion; + }(Lion, Animal); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Lion); + function Lion() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Lion), _this = _super.apply(this, arguments), _this.sound = "RAWR!", _this; + } + return Lion; }(Animal); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.1.normal/output.js index bb2d3de69b4..052a0c95d5a 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -78,10 +103,11 @@ var A = // @target: esnext var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B(p) { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this)); + _this = _super.call(this); _this.p = p; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.2.minified/output.js index d2824fbf22c..445306cd117 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesAccessors5/input.ts/es5.2.minified/output.js @@ -33,14 +33,7 @@ var A = function() { ], _defineProperties((Constructor = A).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), A; }(), B = function(A) { "use strict"; - function B(p) { - var _this, self, call, obj; - return _classCallCheck(this, B), (_this = (self = this, (call = _getPrototypeOf(B).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p = p, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -49,5 +42,34 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B(p) { + var _this; + return _classCallCheck(this, B), (_this = _super.call(this)).p = p, _this; + } + return B; }(A); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.1.normal/output.js index 79943e25f10..48aedb08314 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // @target: esnext // @useDefineForClassFields: true /*#__PURE__*/ function() { @@ -77,10 +102,11 @@ var A = // @target: esnext var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.m = function() { return 1; }; diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.2.minified/output.js index 8a7c08e4c89..733b66ea6b6 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/propertyOverridesMethod/input.ts/es5.2.minified/output.js @@ -32,16 +32,7 @@ var A = function() { ], _defineProperties((Constructor = A).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), A; }(), B = function(A) { "use strict"; - function B() { - var _this, self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).m = function() { - return 1; - }, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -50,5 +41,36 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + var _this; + return _classCallCheck(this, B), _this = _super.apply(this, arguments), _this.m = function() { + return 1; + }, _this; + } + return B; }(A); diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.1.normal/output.js index ddab8d740f3..d96169b837b 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = // @target: esnext // @allowjs: true // @noemit: true @@ -84,10 +109,11 @@ var Bar = // @Filename: bar.js /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Bar).call(this)); + _this = _super.call(this); _this.p = 2; return _this; } diff --git a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.2.minified/output.js index 8b67581cbe8..56d8ea9e3ce 100644 --- a/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var Foo = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Foo; }(), Bar = function(Foo) { "use strict"; - function Bar() { - var _this, self, call, obj; - return _classCallCheck(this, Bar), (_this = (self = this, (call = _getPrototypeOf(Bar).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p = 2, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,5 +44,34 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + var _this; + return _classCallCheck(this, Bar), (_this = _super.call(this)).p = 2, _this; + } + return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.1.normal/output.js index 20d312f995e..6bef6f5c481 100644 --- a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.1.normal/output.js @@ -65,6 +65,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @declaration: true // @module: commonjs export var C = /*#__PURE__*/ function() { @@ -85,9 +110,10 @@ export var C = /*#__PURE__*/ function() { export var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.2.minified/output.js index fa5855bfb5c..1fa64e1a295 100644 --- a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicates01/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ export var _typeof, C = function() { }(); export var D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,5 +44,33 @@ export var D = function(C) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C); diff --git a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.1.normal/output.js index e09c1eb4183..3c5e7909340 100644 --- a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.1.normal/output.js @@ -65,6 +65,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @declaration: true // @module: commonjs export var C = /*#__PURE__*/ function() { @@ -85,9 +110,10 @@ export var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.2.minified/output.js index fe34925f1fd..922f2d10b80 100644 --- a/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ export var _typeof, C = function() { }(); var D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,5 +44,33 @@ var D = function(C) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C); diff --git a/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.1.normal/output.js index 6c8a6c7943e..4d05f677ead 100644 --- a/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.1.normal/output.js @@ -191,6 +191,31 @@ function _wrapAsyncGenerator(fn) { return new AsyncGenerator(fn.apply(this, arguments)); }; } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = // @target: es2015 // @lib: esnext // @filename: C1.ts @@ -453,9 +478,10 @@ var B9 = // @filename: C9.ts var C9 = /*#__PURE__*/ function(B9) { "use strict"; _inherits(C9, B9); + var _super = _createSuper(C9); function C9() { _classCallCheck(this, C9); - return _possibleConstructorReturn(this, _getPrototypeOf(C9).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C9, [ { diff --git a/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.2.minified/output.js index 72cb638539f..3c6981f59cd 100644 --- a/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/emitter/es2015/asyncGenerators/emitter.asyncGenerators.classMethods.es2015/input.ts/es5.2.minified/output.js @@ -334,14 +334,7 @@ var C1 = function() { ]), B9; }(), C9 = function(B9) { "use strict"; - function C9() { - var self, call, obj; - return _classCallCheck(this, C9), self = this, call = _getPrototypeOf(C9).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -350,7 +343,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C9, B9), _createClass(C9, [ + }(C9, B9); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C9); + function C9() { + return _classCallCheck(this, C9), _super.apply(this, arguments); + } + return _createClass(C9, [ { key: "f", value: function() { diff --git a/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.1.normal/output.js index bf594d39dc2..94e26aa08f8 100644 --- a/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.1.normal/output.js @@ -191,6 +191,31 @@ function _wrapAsyncGenerator(fn) { return new AsyncGenerator(fn.apply(this, arguments)); }; } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = // @target: es2018 // @lib: esnext // @filename: C1.ts @@ -453,9 +478,10 @@ var B9 = // @filename: C9.ts var C9 = /*#__PURE__*/ function(B9) { "use strict"; _inherits(C9, B9); + var _super = _createSuper(C9); function C9() { _classCallCheck(this, C9); - return _possibleConstructorReturn(this, _getPrototypeOf(C9).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C9, [ { diff --git a/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.2.minified/output.js index 72cb638539f..3c6981f59cd 100644 --- a/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/emitter/es2018/asyncGenerators/emitter.asyncGenerators.classMethods.es2018/input.ts/es5.2.minified/output.js @@ -334,14 +334,7 @@ var C1 = function() { ]), B9; }(), C9 = function(B9) { "use strict"; - function C9() { - var self, call, obj; - return _classCallCheck(this, C9), self = this, call = _getPrototypeOf(C9).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -350,7 +343,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C9, B9), _createClass(C9, [ + }(C9, B9); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C9); + function C9() { + return _classCallCheck(this, C9), _super.apply(this, arguments); + } + return _createClass(C9, [ { key: "f", value: function() { diff --git a/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.1.normal/output.js index 608e0f021b9..20cab9fa55a 100644 --- a/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.1.normal/output.js @@ -191,6 +191,31 @@ function _wrapAsyncGenerator(fn) { return new AsyncGenerator(fn.apply(this, arguments)); }; } +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = // @target: es5 // @lib: esnext // @filename: C1.ts @@ -453,9 +478,10 @@ var B9 = // @filename: C9.ts var C9 = /*#__PURE__*/ function(B9) { "use strict"; _inherits(C9, B9); + var _super = _createSuper(C9); function C9() { _classCallCheck(this, C9); - return _possibleConstructorReturn(this, _getPrototypeOf(C9).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C9, [ { diff --git a/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.2.minified/output.js index 72cb638539f..3c6981f59cd 100644 --- a/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/emitter/es5/asyncGenerators/emitter.asyncGenerators.classMethods.es5/input.ts/es5.2.minified/output.js @@ -334,14 +334,7 @@ var C1 = function() { ]), B9; }(), C9 = function(B9) { "use strict"; - function C9() { - var self, call, obj; - return _classCallCheck(this, C9), self = this, call = _getPrototypeOf(C9).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -350,7 +343,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C9, B9), _createClass(C9, [ + }(C9, B9); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C9); + function C9() { + return _classCallCheck(this, C9), _super.apply(this, arguments); + } + return _createClass(C9, [ { key: "f", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.1.normal/output.js index c9fc7cb6245..297934599a2 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var tmp = Symbol.toStringTag; var C1 = //@target: ES6 /*#__PURE__*/ function() { @@ -79,9 +104,10 @@ var tmp1 = Symbol.toStringTag; var C2 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(C2, C1); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C2, [ { diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.2.minified/output.js index b74fb0a241b..5f6d02f9f98 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty26/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var tmp = Symbol.toStringTag, C1 = function() { ]), C1; }(), tmp1 = Symbol.toStringTag, C2 = function(C1) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var tmp = Symbol.toStringTag, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C1), _createClass(C2, [ + }(C2, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return _createClass(C2, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.1.normal/output.js index ef26361f16e..863f2b726bd 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var tmp = Symbol.toStringTag; var C1 = //@target: ES6 /*#__PURE__*/ function() { @@ -80,9 +105,10 @@ var tmp1 = Symbol.toStringTag; var C2 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(C2, C1); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C2, [ { diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.2.minified/output.js index a229f282789..352eb2bd312 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty27/input.ts/es5.2.minified/output.js @@ -36,14 +36,7 @@ var tmp = Symbol.toStringTag, C1 = function() { ]), C1; }(), tmp1 = Symbol.toStringTag, C2 = function(C1) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -52,7 +45,35 @@ var tmp = Symbol.toStringTag, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C1), _createClass(C2, [ + }(C2, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return _createClass(C2, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.1.normal/output.js index 458eb9b48c6..f14d2f46864 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var tmp = Symbol.toStringTag; var C1 = //@target: ES6 /*#__PURE__*/ function() { @@ -80,9 +105,10 @@ var C1 = //@target: ES6 var C2 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(C2, C1); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(C1); diff --git a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.2.minified/output.js index 86228ca412c..fec68cb1d7f 100644 --- a/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/Symbols/symbolProperty28/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var c, tmp = Symbol.toStringTag, C1 = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C1; }(), C2 = function(C1) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,6 +44,34 @@ var c, tmp = Symbol.toStringTag, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C1), C2; + }(C2, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return C2; }(C1); c[Symbol.toStringTag]().x; diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.1.normal/output.js index 9e5ed1304cc..a4bd87312c2 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B(a) { "use strict"; _classCallCheck(this, B); @@ -51,18 +76,20 @@ var B = function B(a) { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); var D = /*#__PURE__*/ function(B) { "use strict"; _inherits(D, B); + var _super = _createSuper(D); function D(b) { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, b)); + return _super.call(this, b); } return D; }(B); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.2.minified/output.js index dea1421fce1..2eb98c84ac5 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, B1 = function(a) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var B1 = function(a) { "use strict"; _classCallCheck(this, B1); }, C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), C; + return C; }(B1), D = function(B) { "use strict"; + _inherits(D, B); + var _super = _createSuper(D); function D(b) { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, b)); + return _classCallCheck(this, D), _super.call(this, b); } - return _inherits(D, B), D; + return D; }(B1); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.1.normal/output.js index 5eeb15eb278..93e27d8db63 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -100,9 +125,10 @@ var B = // @target: es6 var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { @@ -122,9 +148,10 @@ var C = /*#__PURE__*/ function(B) { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).call(this)); + return _super.call(this); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.2.minified/output.js index 67607e680e1..c9715a444db 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithExtensionInES6/input.ts/es5.2.minified/output.js @@ -34,12 +34,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -49,9 +43,31 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, B = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var B = function() { "use strict"; function B() { _classCallCheck(this, B); @@ -65,10 +81,12 @@ var _typeof = function(obj) { ]), B; }(), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), _createClass(C, [ + return _createClass(C, [ { key: "foo", value: function() { @@ -83,10 +101,12 @@ var _typeof = function(obj) { ]), C; }(B), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).call(this)); + return _classCallCheck(this, D), _super.call(this); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.1.normal/output.js index 9186915e7a8..c2f540789d7 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var B = function B() { "use strict"; _classCallCheck(this, B); @@ -56,9 +81,10 @@ function foo() { var C = /*#__PURE__*/ function(_B) { "use strict"; _inherits(C, _B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(foo().B); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.2.minified/output.js index 61434d74f4b..dd63e28e297 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAccessInHeritageClause1/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var B = function() { _classCallCheck(this, B); }, C = function(_B) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var B = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, _B), C; + }(C, _B); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return C; }(B); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.1.normal/output.js index bc08af2f102..ee02255e7ae 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -59,10 +84,11 @@ var D = function D() { var E = /*#__PURE__*/ function(D) { "use strict"; _inherits(E, D); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.z = true; return _this; } @@ -71,10 +97,11 @@ var E = /*#__PURE__*/ function(D) { var F = /*#__PURE__*/ function(D) { "use strict"; _inherits(F, D); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(F).call(this)); + _this = _super.call(this); _this.z = true; _this.j = "HI"; return _this; diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.2.minified/output.js index 17945015aeb..4a8c26146f6 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function() { "use strict"; _classCallCheck(this, C), this.x = "Hello world"; }, D1 = function() { @@ -37,16 +53,20 @@ var _typeof = function(obj) { _classCallCheck(this, D1), this.x = "Hello world", this.y = 10; }, E = function(D) { "use strict"; + _inherits(E, D); + var _super = _createSuper(E); function E() { var _this; - return _classCallCheck(this, E), _this = _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)), _this.z = !0, _this; + return _classCallCheck(this, E), _this = _super.apply(this, arguments), _this.z = !0, _this; } - return _inherits(E, D), E; + return E; }(D1), F = function(D) { "use strict"; + _inherits(F, D); + var _super = _createSuper(F); function F() { var _this; - return _classCallCheck(this, F), (_this = _possibleConstructorReturn(this, _getPrototypeOf(F).call(this))).z = !0, _this.j = "HI", _this; + return _classCallCheck(this, F), (_this = _super.call(this)).z = !0, _this.j = "HI", _this; } - return _inherits(F, D), F; + return F; }(D1); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.1.normal/output.js index a1a4df4f2d4..058d49b18bb 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Parent = //@target: es6 /*#__PURE__*/ function() { "use strict"; @@ -99,9 +124,10 @@ var Parent = //@target: es6 var Foo = /*#__PURE__*/ function(Parent) { "use strict"; _inherits(Foo, Parent); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Foo, [ { diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.2.minified/output.js index 62c41a9a2aa..dac0de21b52 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01/input.ts/es5.2.minified/output.js @@ -47,14 +47,7 @@ var Parent = function() { ]), Parent; }(), Foo = function(Parent) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -63,7 +56,35 @@ var Parent = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Parent), _createClass(Foo, [ + }(Foo, Parent); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return _createClass(Foo, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.1.normal/output.js index ab4a338c3e0..972421280d4 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(c) { "use strict"; _classCallCheck(this, Base); @@ -51,10 +76,11 @@ var Base = function Base(c) { var D = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D, Base); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, i)); + _this = _super.call(this, i); var s = { t: _this._t }; diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.2.minified/output.js index 43d540537b6..02f14b5aee6 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing1/input.ts/es5.2.minified/output.js @@ -16,17 +16,7 @@ var Base1 = function(c) { _classCallCheck(this, Base1); }, D = function(Base) { "use strict"; - function D() { - _classCallCheck(this, D); - var obj, self, call, _this, s = { - t: (_this = (self = this, (call = _getPrototypeOf(D).call(this, i)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - }(self)))._t - }, i = Factory.create(s); - return _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,5 +25,37 @@ var Base1 = function(c) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, Base), D; + }(D, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + _classCallCheck(this, D); + var _this, s = { + t: (_this = _super.call(this, i))._t + }, i = Factory.create(s); + return _this; + } + return D; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.1.normal/output.js index f68582a8186..4a14690352a 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(c) { "use strict"; _classCallCheck(this, Base); @@ -51,12 +76,13 @@ var Base = function Base(c) { var D = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D, Base); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, function() { + _this = _super.call(this, function() { _this._t; - })); // no error. only check when this is directly accessing in constructor + }); // no error. only check when this is directly accessing in constructor return _this; } return D; diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.2.minified/output.js index 3cad8c14912..23c35596486 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing2/input.ts/es5.2.minified/output.js @@ -16,16 +16,7 @@ var Base1 = function(c) { _classCallCheck(this, Base1); }, D = function(Base) { "use strict"; - function D() { - var _this, self, call, obj; - return _classCallCheck(this, D), self = this, _this = (call = _getPrototypeOf(D).call(this, function() { - _this._t; - })) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,5 +25,36 @@ var Base1 = function(c) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, Base), D; + }(D, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + var _this; + return _classCallCheck(this, D), _this = _super.call(this, function() { + _this._t; + }); + } + return D; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.1.normal/output.js index bea3b9737a1..b7367ef7aec 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.1.normal/output.js @@ -9,6 +9,12 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); @@ -38,9 +44,35 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var D = /*#__PURE__*/ function(_super) { "use strict"; _inherits(D, _super); + var _super1 = _createSuper(D); function D() { _classCallCheck(this, D); var _this; diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.2.minified/output.js index 3acfd790f86..a48f31d12f4 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing5/input.ts/es5.2.minified/output.js @@ -1,3 +1,8 @@ +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -14,7 +19,7 @@ var D = function(_super) { return self; })(self); } - return !function(subClass, superClass) { + return (function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -23,5 +28,15 @@ var D = function(_super) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, null), D; + })(D, null), (function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + } catch (e) { + return !1; + } + })(), D; }(null); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.1.normal/output.js index 1dc787f5937..1e90685e3be 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(c) { "use strict"; _classCallCheck(this, Base); @@ -51,11 +76,12 @@ var Base = function Base(c) { var D = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D, Base); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; var x = { - k: _this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, undefined)), + k: _this = _super.call(this, undefined), j: _this._t }; return _possibleConstructorReturn(_this); diff --git a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.2.minified/output.js index 24740e784b7..9ff12dc711e 100644 --- a/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classDeclaration/superCallBeforeThisAccessing8/input.ts/es5.2.minified/output.js @@ -24,11 +24,7 @@ var _typeof = function(obj) { _classCallCheck(this, Base1); }, D = function(Base) { "use strict"; - function D() { - var _this; - return _classCallCheck(this, D), (_this = _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, void 0)))._t, _possibleConstructorReturn(_this); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -37,5 +33,31 @@ var _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, Base), D; + }(D, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return _possibleConstructorReturn(this, result); + }; + }(D); + function D() { + var _this; + return _classCallCheck(this, D), (_this = _super.call(this, void 0))._t, _possibleConstructorReturn(_this); + } + return D; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.1.normal/output.js index c97e622dab9..07b59b099af 100644 --- a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var D = function D() { "use strict"; _classCallCheck(this, D); @@ -51,9 +76,10 @@ var D = function D() { var v = /*#__PURE__*/ function(D) { "use strict"; _inherits(C, D); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(D); diff --git a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.2.minified/output.js index 836ae927e84..7b8fae4cc3d 100644 --- a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES62/input.ts/es5.2.minified/output.js @@ -17,13 +17,6 @@ var D1 = function() { }; !function(D) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { @@ -34,4 +27,31 @@ var D1 = function() { } }), superClass && _setPrototypeOf(subClass, superClass); }(C, D); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } }(D1); diff --git a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.1.normal/output.js index 2c2de73dd43..ff03530369f 100644 --- a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.1.normal/output.js @@ -44,14 +44,40 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: es6 var C = /*#__PURE__*/ function(_super) { "use strict"; _inherits(_class, _super); + var _super1 = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super1.apply(this, arguments); _this.c = 3; return _this; } @@ -59,10 +85,11 @@ var C = /*#__PURE__*/ function(_super) { }(/*#__PURE__*/ function(_super) { "use strict"; _inherits(_class, _super); + var _super2 = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + _this = _super2.apply(this, arguments); _this.b = 2; return _this; } diff --git a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.2.minified/output.js index c494fbe100c..e8588f14e6b 100644 --- a/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/classExpressions/classExpressionES63/input.ts/es5.2.minified/output.js @@ -16,33 +16,53 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, c = new (function(_super) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var c = new (function(_super) { "use strict"; + _inherits(_class, _super); + var _super1 = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.c = 3, _this; + return _classCallCheck(this, _class), _this = _super1.apply(this, arguments), _this.c = 3, _this; } - return _inherits(_class, _super), _class; + return _class; }(function(_super) { "use strict"; + _inherits(_class, _super); + var _super2 = _createSuper(_class); function _class() { var _this; - return _classCallCheck(this, _class), _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)), _this.b = 2, _this; + return _classCallCheck(this, _class), _this = _super2.apply(this, arguments), _this.b = 2, _this; } - return _inherits(_class, _super), _class; + return _class; }(function _class() { "use strict"; _classCallCheck(this, _class), this.a = 1; diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.1.normal/output.js index 76692b8213f..72bfeae4168 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es5 /*#__PURE__*/ function() { "use strict"; @@ -78,9 +103,10 @@ var tmp = super.bar(); var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.2.minified/output.js index 4f2cb657285..20fdeddcaf0 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES5/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var Base = function() { ]), Base; }(), tmp = super.bar(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.1.normal/output.js index 1aa754932d5..bcd883e25dc 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -78,9 +103,10 @@ var tmp = super.bar(); var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.2.minified/output.js index 4f2cb657285..20fdeddcaf0 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames24_ES6/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var Base = function() { ]), Base; }(), tmp = super.bar(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.1.normal/output.js index 3efc079c922..9dc74e30d95 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.1.normal/output.js @@ -94,6 +94,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es5 /*#__PURE__*/ function() { "use strict"; @@ -113,9 +138,10 @@ var Base = // @target: es5 var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.2.minified/output.js index 234920500c0..a09c94a6f91 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES5/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var Base = function() { ]), Base; }(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.1.normal/output.js index 6df2289029d..15c80e2f8dc 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.1.normal/output.js @@ -94,6 +94,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -113,9 +138,10 @@ var Base = // @target: es6 var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.2.minified/output.js index 234920500c0..a09c94a6f91 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames25_ES6/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var Base = function() { ]), Base; }(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.1.normal/output.js index 0726eab786e..8cd1de4437d 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.1.normal/output.js @@ -71,6 +71,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es5 /*#__PURE__*/ function() { "use strict"; @@ -92,9 +117,10 @@ var tmp = _defineProperty({ var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.2.minified/output.js index b3d8505322c..1273fe26f39 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES5/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var obj, key, Base = function() { writable: !0 }) : obj[key] = 1, obj)[0], C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var obj, key, Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.1.normal/output.js index 8c436827437..0c64d5bae7f 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.1.normal/output.js @@ -71,6 +71,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -92,9 +117,10 @@ var tmp = _defineProperty({ var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.2.minified/output.js index b3d8505322c..1273fe26f39 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames26_ES6/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var obj, key, Base = function() { writable: !0 }) : obj[key] = 1, obj)[0], C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var obj, key, Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.1.normal/output.js index 232f438451a..94a6bbc4a91 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -66,9 +91,10 @@ var tmp = (super(), "prop"); var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.2.minified/output.js index ac26e8c03d3..2deec72f097 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES5/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var Base1 = function() { _classCallCheck(this, Base1); }, tmp = (super(), "prop"), C = function(Base) { "use strict"; - var Constructor, protoProps, staticProps; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), Constructor = C, protoProps = [ + }(C, Base); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return Constructor = C, protoProps = [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.1.normal/output.js index 232f438451a..94a6bbc4a91 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -66,9 +91,10 @@ var tmp = (super(), "prop"); var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.2.minified/output.js index ac26e8c03d3..2deec72f097 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames27_ES6/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var Base1 = function() { _classCallCheck(this, Base1); }, tmp = (super(), "prop"), C = function(Base) { "use strict"; - var Constructor, protoProps, staticProps; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), Constructor = C, protoProps = [ + }(C, Base); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return Constructor = C, protoProps = [ { key: tmp, value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.1.normal/output.js index 0aa1d4c159f..6fb97ade58e 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.1.normal/output.js @@ -57,6 +57,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -64,12 +89,13 @@ var Base = function Base() { var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)); + _this = _super.call(this); var obj = _defineProperty({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { + }, (_this = _super.call(this), "prop"), function() { }); return _this; } diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.2.minified/output.js index d87b32bbada..e497006ce22 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES5/input.ts/es5.2.minified/output.js @@ -6,38 +6,17 @@ function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }, _getPrototypeOf(o); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, C = function(Base) { "use strict"; - function C() { - var _this; - return _classCallCheck(this, C), _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), (function(obj, key, value) { - key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 - }) : obj[key] = value; - })({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { - }), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,5 +25,43 @@ var _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + var _this; + return _classCallCheck(this, C), _this = _super.call(this), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + })({ + }, (_this = _super.call(this), "prop"), function() { + }), _this; + } + return C; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.1.normal/output.js index 0aa1d4c159f..6fb97ade58e 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.1.normal/output.js @@ -57,6 +57,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -64,12 +89,13 @@ var Base = function Base() { var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)); + _this = _super.call(this); var obj = _defineProperty({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { + }, (_this = _super.call(this), "prop"), function() { }); return _this; } diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.2.minified/output.js index d87b32bbada..e497006ce22 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames28_ES6/input.ts/es5.2.minified/output.js @@ -6,38 +6,17 @@ function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }, _getPrototypeOf(o); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, C = function(Base) { "use strict"; - function C() { - var _this; - return _classCallCheck(this, C), _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), (function(obj, key, value) { - key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 - }) : obj[key] = value; - })({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { - }), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,5 +25,43 @@ var _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + var _this; + return _classCallCheck(this, C), _this = _super.call(this), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + })({ + }, (_this = _super.call(this), "prop"), function() { + }), _this; + } + return C; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.1.normal/output.js index c2994a7ee65..6b3bce36383 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.1.normal/output.js @@ -57,6 +57,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -64,17 +89,18 @@ var Base = function Base() { var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { var _this = this; _classCallCheck(this, C); var _this1; - _this1 = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)); + _this1 = _super.call(this); (function() { var obj = // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. _defineProperty({ - }, (_this1 = _possibleConstructorReturn(_this, _getPrototypeOf(C).call(_this)), "prop"), function() { + }, (_this1 = _super.call(_this), "prop"), function() { }); }); return _this1; diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.2.minified/output.js index 2bebb01a5ed..be9e3c5df67 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES5/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var Base1 = function() { _classCallCheck(this, Base1); }, C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, (call = _getPrototypeOf(C).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.call(this); + } + return C; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.1.normal/output.js index c2994a7ee65..6b3bce36383 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.1.normal/output.js @@ -57,6 +57,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -64,17 +89,18 @@ var Base = function Base() { var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { var _this = this; _classCallCheck(this, C); var _this1; - _this1 = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)); + _this1 = _super.call(this); (function() { var obj = // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. _defineProperty({ - }, (_this1 = _possibleConstructorReturn(_this, _getPrototypeOf(C).call(_this)), "prop"), function() { + }, (_this1 = _super.call(_this), "prop"), function() { }); }); return _this1; diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.2.minified/output.js index 2bebb01a5ed..be9e3c5df67 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames30_ES6/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var Base1 = function() { _classCallCheck(this, Base1); }, C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, (call = _getPrototypeOf(C).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.call(this); + } + return C; }(Base1); diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.1.normal/output.js index 27be4e7a9f1..4430fe11bd9 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.1.normal/output.js @@ -94,6 +94,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es5 /*#__PURE__*/ function() { "use strict"; @@ -113,9 +138,10 @@ var Base = // @target: es5 var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.2.minified/output.js index c62ef7989de..037dc2baa23 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES5/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var Base = function() { ]), Base; }(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.1.normal/output.js index 9e79cc8e805..f1c71c2d106 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.1.normal/output.js @@ -94,6 +94,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: es6 /*#__PURE__*/ function() { "use strict"; @@ -113,9 +138,10 @@ var Base = // @target: es6 var C = /*#__PURE__*/ function(Base) { "use strict"; _inherits(C, Base); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.2.minified/output.js index c62ef7989de..037dc2baa23 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames31_ES6/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var Base = function() { ]), Base; }(), C = function(Base) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), _createClass(C, [ + }(C, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return _createClass(C, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.1.normal/output.js index ef220fa57e3..9d873131a52 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -74,9 +99,10 @@ var tmp = "get1", tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.2.minified/output.js index 6068cf925af..0280f9593c9 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES5/input.ts/es5.2.minified/output.js @@ -28,15 +28,7 @@ var Foo = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - var Constructor, protoProps, staticProps; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -45,7 +37,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), Constructor = D, protoProps = [ + }(D, C); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return Constructor = D, protoProps = [ { key: "get1", get: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.1.normal/output.js index ef220fa57e3..9d873131a52 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -74,9 +99,10 @@ var tmp = "get1", tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.2.minified/output.js index 6068cf925af..0280f9593c9 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames43_ES6/input.ts/es5.2.minified/output.js @@ -28,15 +28,7 @@ var Foo = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - var Constructor, protoProps, staticProps; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -45,7 +37,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), Constructor = D, protoProps = [ + }(D, C); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return Constructor = D, protoProps = [ { key: "get1", get: function() { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.1.normal/output.js index d1598cbd7d2..cf7ee152ee5 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -86,9 +111,10 @@ var tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.2.minified/output.js index 0f4149a7e0c..cb16141d136 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES5/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var Foo = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "set1", set: function(p) { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.1.normal/output.js index d1598cbd7d2..cf7ee152ee5 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -86,9 +111,10 @@ var tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.2.minified/output.js index 0f4149a7e0c..cb16141d136 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames44_ES6/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var Foo = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "set1", set: function(p) { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.1.normal/output.js index d1598cbd7d2..cf7ee152ee5 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -86,9 +111,10 @@ var tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.2.minified/output.js index 0f4149a7e0c..cb16141d136 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES5/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var Foo = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "set1", set: function(p) { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.1.normal/output.js index d1598cbd7d2..cf7ee152ee5 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -86,9 +111,10 @@ var tmp1 = "set1"; var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.2.minified/output.js index 0f4149a7e0c..cb16141d136 100644 --- a/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/computedProperties/computedPropertyNames45_ES6/input.ts/es5.2.minified/output.js @@ -41,14 +41,7 @@ var Foo = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -57,7 +50,35 @@ var Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "set1", set: function(p) { diff --git a/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.1.normal/output.js index 8cab328ec31..ca1b61252ae 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Class = function Class() { "use strict"; _classCallCheck(this, Class); @@ -51,9 +76,10 @@ var Class = function Class() { var SubClass = /*#__PURE__*/ function(Class) { "use strict"; _inherits(SubClass, Class); + var _super = _createSuper(SubClass); function SubClass() { _classCallCheck(this, SubClass); - return _possibleConstructorReturn(this, _getPrototypeOf(SubClass).call(this)); + return _super.call(this); } return SubClass; }(Class); @@ -64,9 +90,10 @@ var D = function D() { var SubD = /*#__PURE__*/ function(D) { "use strict"; _inherits(SubD, D); + var _super = _createSuper(SubD); function SubD() { _classCallCheck(this, SubD); - return _possibleConstructorReturn(this, _getPrototypeOf(SubD).call(this)); + return _super.call(this); } return SubD; }(D); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.2.minified/output.js index 2c1bedae7a8..884a6f75813 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/destructuringParameterDeclaration5/input.ts/es5.2.minified/output.js @@ -16,37 +16,57 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Class1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Class1 = function() { "use strict"; _classCallCheck(this, Class1); }, SubClass = function(Class) { "use strict"; + _inherits(SubClass, Class); + var _super = _createSuper(SubClass); function SubClass() { - return _classCallCheck(this, SubClass), _possibleConstructorReturn(this, _getPrototypeOf(SubClass).call(this)); + return _classCallCheck(this, SubClass), _super.call(this); } - return _inherits(SubClass, Class), SubClass; + return SubClass; }(Class1), D1 = function() { "use strict"; _classCallCheck(this, D1); }, SubD = function(D) { "use strict"; + _inherits(SubD, D); + var _super = _createSuper(SubD); function SubD() { - return _classCallCheck(this, SubD), _possibleConstructorReturn(this, _getPrototypeOf(SubD).call(this)); + return _classCallCheck(this, SubD), _super.call(this); } - return _inherits(SubD, D), SubD; + return SubD; }(D1); function d0(param) { (void 0 === param ? { diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.1.normal/output.js index f55cfb6e948..f9ef19d8cbe 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -96,9 +121,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.2.minified/output.js index 05e35384f0c..e0121e6df37 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern10/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.1.normal/output.js index 593cf4395c3..05bb7461df1 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -96,9 +121,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.2.minified/output.js index 824e90c2b10..bece2eebeb0 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern11/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.1.normal/output.js index a31b314eacf..d211655de6d 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.1.normal/output.js @@ -70,6 +70,31 @@ function _toArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -77,9 +102,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.2.minified/output.js index b69543c1421..d47d6f4a29c 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern12/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.1.normal/output.js index 7a6deb5d7db..279a74bf42a 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.1.normal/output.js @@ -70,6 +70,31 @@ function _toArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -77,9 +102,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.2.minified/output.js index 4059c1689f9..d3edc998e0f 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern13/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.1.normal/output.js index 68a1edd51eb..3a4e32a6ff5 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.1.normal/output.js @@ -70,6 +70,31 @@ function _toArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -77,9 +102,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.2.minified/output.js index c5bb3651cb0..a695afc81c9 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern14/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.1.normal/output.js index 8ab8d35500f..9de7beab21a 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.1.normal/output.js @@ -106,6 +106,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -113,9 +138,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.2.minified/output.js index 84ee5021b20..cb92d3dc9ee 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern15/input.ts/es5.2.minified/output.js @@ -24,14 +24,7 @@ var arr, _typeof = function(obj) { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -40,7 +33,35 @@ var arr, _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.1.normal/output.js index 416cd3ebc3a..85d6c168736 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.1.normal/output.js @@ -106,6 +106,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES6 function fun() { for(var _len = arguments.length, _tmp = new Array(_len), _key = 0; _key < _len; _key++){ @@ -121,9 +146,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.2.minified/output.js index 3d16e3c7863..043e4fab5de 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern16/input.ts/es5.2.minified/output.js @@ -60,14 +60,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -76,7 +69,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; function FooIterator() { diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.1.normal/output.js index 61eaa3f5855..fbf6dcc6549 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -96,9 +121,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.2.minified/output.js index a14800f567c..54e2e44ea7d 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern17/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.1.normal/output.js index f55cfb6e948..f9ef19d8cbe 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -96,9 +121,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.2.minified/output.js index 05e35384f0c..e0121e6df37 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern18/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.1.normal/output.js index ad6a4a4c812..16b8f738858 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -96,9 +121,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.2.minified/output.js index 98a2045fd18..52cf794b0ce 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern19/input.ts/es5.2.minified/output.js @@ -43,14 +43,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -59,7 +52,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooArrayIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.1.normal/output.js index 32d369b9e22..fd29f00eba1 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.1.normal/output.js @@ -106,6 +106,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -113,9 +138,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.2.minified/output.js index 8a9fd3c6230..ffbff607efd 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern20/input.ts/es5.2.minified/output.js @@ -45,14 +45,7 @@ var arr, _typeof = function(obj) { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -61,7 +54,35 @@ var arr, _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooArrayIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.1.normal/output.js index a05f52ad3cd..0608d33e5bd 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.2.minified/output.js index ef3ce82feff..14e168a8796 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern3/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.1.normal/output.js index fbf8e4db87e..ad394cfea8f 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.2.minified/output.js index bf8a536bc5e..23853f3c3a1 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern4/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.1.normal/output.js index a05f52ad3cd..0608d33e5bd 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.2.minified/output.js index ef3ce82feff..14e168a8796 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern5/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.1.normal/output.js index fbf8e4db87e..ad394cfea8f 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.2.minified/output.js index bf8a536bc5e..23853f3c3a1 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern6/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.1.normal/output.js index a05f52ad3cd..0608d33e5bd 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.2.minified/output.js index ef3ce82feff..14e168a8796 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern7/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.1.normal/output.js index fbf8e4db87e..ad394cfea8f 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Bar = function Bar() { "use strict"; _classCallCheck(this, Bar); @@ -65,9 +90,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.2.minified/output.js index bf8a536bc5e..23853f3c3a1 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern8/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ref, Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ref, Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.1.normal/output.js index 2c9f218a0ca..c2a72b82f34 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.1.normal/output.js @@ -89,6 +89,31 @@ function _slicedToArray(arr, i) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES6 function fun(param) { var ref = _slicedToArray(param === void 0 ? new FooIterator : param, 2), a = ref[0], b = ref[1]; @@ -100,9 +125,10 @@ var Bar = function Bar() { var Foo = /*#__PURE__*/ function(Bar) { "use strict"; _inherits(Foo, Bar); + var _super = _createSuper(Foo); function Foo() { _classCallCheck(this, Foo); - return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments)); + return _super.apply(this, arguments); } return Foo; }(Bar); diff --git a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.2.minified/output.js index b95f9b32252..5ecd4f88807 100644 --- a/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/destructuring/iterableArrayPattern9/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var Bar1 = function() { _classCallCheck(this, Bar1); }, Foo = function(Bar) { "use strict"; - function Foo() { - var self, call, obj; - return _classCallCheck(this, Foo), self = this, call = _getPrototypeOf(Foo).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var Bar1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Foo, Bar), Foo; + }(Foo, Bar); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Foo); + function Foo() { + return _classCallCheck(this, Foo), _super.apply(this, arguments); + } + return Foo; }(Bar1), tmp = Symbol.iterator, FooIterator = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.1.normal/output.js index 0565db00c98..3331281c8a4 100644 --- a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.1.normal/output.js @@ -51,6 +51,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -71,11 +96,12 @@ A.c = function _target() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; var _newtarget = _this.constructor; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this)); + _this = _super.call(this); var e = _this.constructor; var f = function() { return _newtarget; diff --git a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.2.minified/output.js index c844df4134c..0e952c6c0bc 100644 --- a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es5/input.ts/es5.2.minified/output.js @@ -27,14 +27,7 @@ A1.c = function _target() { }; var B = function(A) { "use strict"; - function B() { - var _this, self, call, obj; - return _classCallCheck(this, B), _this.constructor, (_this = (self = this, (call = _getPrototypeOf(B).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).constructor, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -43,7 +36,36 @@ var B = function(A) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + var _this; + return _classCallCheck(this, B), _this.constructor, (_this = _super.call(this)).constructor, _this; + } + return B; }(A1); function f1() { _instanceof(this, f1) && this.constructor, _instanceof(this, f1) && this.constructor; diff --git a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.1.normal/output.js index 833c9d19848..75c6640e1b4 100644 --- a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.1.normal/output.js @@ -51,6 +51,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -71,11 +96,12 @@ A.c = function _target() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); var _this; var _newtarget = _this.constructor; - _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this)); + _this = _super.call(this); var e = _this.constructor; var f = function() { return _newtarget; diff --git a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.2.minified/output.js index c844df4134c..0e952c6c0bc 100644 --- a/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/newTarget/newTarget.es6/input.ts/es5.2.minified/output.js @@ -27,14 +27,7 @@ A1.c = function _target() { }; var B = function(A) { "use strict"; - function B() { - var _this, self, call, obj; - return _classCallCheck(this, B), _this.constructor, (_this = (self = this, (call = _getPrototypeOf(B).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).constructor, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -43,7 +36,36 @@ var B = function(A) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + var _this; + return _classCallCheck(this, B), _this.constructor, (_this = _super.call(this)).constructor, _this; + } + return B; }(A1); function f1() { _instanceof(this, f1) && this.constructor, _instanceof(this, f1) && this.constructor; diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.1.normal/output.js index 973567d7122..9615736d040 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.2.minified/output.js index 2cbb9bdecdc..32ae606000d 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck17/input.ts/es5.2.minified/output.js @@ -30,14 +30,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,5 +39,33 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.1.normal/output.js index 764e078c308..f69a1d28350 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.2.minified/output.js index 6dfc2b48c2c..6bf098e602b 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck19/input.ts/es5.2.minified/output.js @@ -32,14 +32,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -48,5 +41,33 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.1.normal/output.js index ca3ac649f78..9f57fd35386 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.2.minified/output.js index 84610799f17..27a1b11f6a0 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck21/input.ts/es5.2.minified/output.js @@ -30,14 +30,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,5 +39,33 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.1.normal/output.js index 6c158611e66..73e3552c9f6 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g3); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.2.minified/output.js index 0dfee90d7dc..5b50f22f764 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck22/input.ts/es5.2.minified/output.js @@ -40,14 +40,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -56,7 +49,35 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1), Baz = function() { "use strict"; _classCallCheck(this, Baz); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.1.normal/output.js index 1874de238da..e16e6a5b4c1 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g3); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.2.minified/output.js index 4982cf6c0ac..0fb30e0e377 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck23/input.ts/es5.2.minified/output.js @@ -42,14 +42,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -58,7 +51,35 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1), Baz = function() { "use strict"; _classCallCheck(this, Baz); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.1.normal/output.js index 097a7e91f15..be73638f55a 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g3); var Foo = function Foo() { "use strict"; @@ -53,9 +78,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.2.minified/output.js index 5c41638b74b..1301eec65ce 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck24/input.ts/es5.2.minified/output.js @@ -44,14 +44,7 @@ var _marked = regeneratorRuntime.mark(function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -60,7 +53,35 @@ var _marked = regeneratorRuntime.mark(function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1), Baz = function() { "use strict"; _classCallCheck(this, Baz); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.1.normal/output.js index 2d0bebb9a98..b9bb2c9c746 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -52,9 +77,10 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.2.minified/output.js index 9d293f2b498..f0439f9d4b4 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck25/input.ts/es5.2.minified/output.js @@ -17,14 +17,7 @@ var Foo1 = function() { _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -33,7 +26,35 @@ var Foo1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), Bar; + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return Bar; }(Foo1), Baz = function() { "use strict"; _classCallCheck(this, Baz); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.1.normal/output.js index 6f2490340a3..ea001d54a0b 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); //@target: ES6 function g() { @@ -55,9 +80,10 @@ function g() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C, _super); + var _super1 = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super1.apply(this, arguments); } return C; }; diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.2.minified/output.js index 1ee05fedf83..3f903659a33 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck40/input.ts/es5.2.minified/output.js @@ -17,30 +17,48 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _marked = regeneratorRuntime.mark(function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _marked = regeneratorRuntime.mark(function() { var C; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: return _ctx.t0 = function(_super) { "use strict"; + _inherits(C, _super); + var _super1 = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super1.apply(this, arguments); } - return _inherits(C, _super), C; + return C; }, _ctx.next = 3, 0; case 3: _ctx.t1 = _ctx.sent, C = (0, _ctx.t0)(_ctx.t1); diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.1.normal/output.js index 8ab6cdabeda..2ca9cb71dbb 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); //@target: ES6 function g() { @@ -55,9 +80,10 @@ function g() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C, _super); + var _super1 = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super1.apply(this, arguments); } return C; }; diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.2.minified/output.js index 9c61dd8dc41..11a598e64dc 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck55/input.ts/es5.2.minified/output.js @@ -17,30 +17,48 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _marked = regeneratorRuntime.mark(function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _marked = regeneratorRuntime.mark(function() { var x; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: _ctx.t0 = function(_super) { "use strict"; + _inherits(C, _super); + var _super1 = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super1.apply(this, arguments); } - return _inherits(C, _super), C; + return C; }, _ctx.next = 3; return; case 3: diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.1.normal/output.js index e9c7d16c9e3..4fd4966c118 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.1.normal/output.js @@ -45,6 +45,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _marked = regeneratorRuntime.mark(g); //@target: ES6 function g() { @@ -55,9 +80,10 @@ function g() { _ctx.t0 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C, _super); + var _super1 = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super1.apply(this, arguments); } return C; }; diff --git a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.2.minified/output.js index e0f9585e695..1a4e7857188 100644 --- a/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/es6/yieldExpressions/generatorTypeCheck60/input.ts/es5.2.minified/output.js @@ -17,30 +17,48 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _marked = regeneratorRuntime.mark(function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _marked = regeneratorRuntime.mark(function() { var C; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: _ctx.t0 = function(_super) { "use strict"; + _inherits(C, _super); + var _super1 = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super1.apply(this, arguments); } - return _inherits(C, _super), C; + return C; }, _ctx.next = 3; return; case 3: diff --git a/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.1.normal/output.js index 20e153a571e..6ff9a6cbf29 100644 --- a/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // Empty array literal with no contextual type has type Undefined[] var arr1 = [ [], @@ -136,18 +161,20 @@ var Base = function Base() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.2.minified/output.js index 197c99373bc..b62b8cc5347 100644 --- a/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/arrayLiterals/arrayLiterals/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function() { "use strict"; _classCallCheck(this, C); }; @@ -39,15 +55,19 @@ var Base1 = function() { _classCallCheck(this, Base1); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); new Derived1(), new Derived2(), new Derived1(), new Derived1(); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.1.normal/output.js index 74f258773cf..028f49b3b31 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A1 = /*#__PURE__*/ function() { "use strict"; function A1() { @@ -106,18 +131,20 @@ var Base = /*#__PURE__*/ function() { var A2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(A2, Base); + var _super = _createSuper(A2); function A2() { _classCallCheck(this, A2); - return _possibleConstructorReturn(this, _getPrototypeOf(A2).apply(this, arguments)); + return _super.apply(this, arguments); } return A2; }(Base); var B2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(B2, Base); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.2.minified/output.js index 1d705328998..2173f49717c 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIdenticalObjects/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; function A1() { _classCallCheck(this, A1); @@ -79,14 +95,18 @@ var _typeof = function(obj) { ]), Base; }(), A2 = function(Base) { "use strict"; + _inherits(A2, Base); + var _super = _createSuper(A2); function A2() { - return _classCallCheck(this, A2), _possibleConstructorReturn(this, _getPrototypeOf(A2).apply(this, arguments)); + return _classCallCheck(this, A2), _super.apply(this, arguments); } - return _inherits(A2, Base), A2; + return A2; }(Base), B2 = function(Base) { "use strict"; + _inherits(B2, Base); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, Base), B2; + return B2; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.1.normal/output.js index 11725bd9603..cfb514f9066 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.2.minified/output.js index d4d95713f6b..5a717df5426 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnCallSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1), C = function() { "use strict"; _classCallCheck(this, C); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.1.normal/output.js index 11725bd9603..cfb514f9066 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.2.minified/output.js index d4d95713f6b..5a717df5426 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnConstructorSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1), C = function() { "use strict"; _classCallCheck(this, C); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.1.normal/output.js index f26238a5dda..b1567453167 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.2.minified/output.js index d4d95713f6b..5a717df5426 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1), C = function() { "use strict"; _classCallCheck(this, C); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js index aee481e44da..685df9d3d67 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js index d4d95713f6b..5a717df5426 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1), C = function() { "use strict"; _classCallCheck(this, C); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js index aee481e44da..685df9d3d67 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js index d4d95713f6b..5a717df5426 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1), C = function() { "use strict"; _classCallCheck(this, C); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.1.normal/output.js index 30879a00286..ca3dc4c994f 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var a1; var b1; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnCallSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.1.normal/output.js index 48b15745505..08b2ba55939 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var a1; var b1; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnConstructorSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.1.normal/output.js index b495df55f20..e4848d5a81b 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var a1; var b1; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnIndexSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js index c67c447ea9d..effb0adc99f 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var a1; var b1; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js index d84b8a10c23..94121bd241b 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var a1; var b1; diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.1.normal/output.js index c1259953d43..2377db47056 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var A1 = function A1() { "use strict"; @@ -72,9 +98,10 @@ var A2 = function A2() { var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); diff --git a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.2.minified/output.js index ebeef1a86b6..d3cbc546bb9 100644 --- a/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnProperty/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), A1 = function() { "use strict"; _classCallCheck(this, A1); @@ -49,8 +67,10 @@ var _typeof = function(obj) { _classCallCheck(this, A21); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A21); diff --git a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.1.normal/output.js index 01741916422..f8130cd3fa7 100644 --- a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var X = function X() { "use strict"; _classCallCheck(this, X); @@ -51,18 +76,20 @@ var X = function X() { var A = /*#__PURE__*/ function(X) { "use strict"; _inherits(A, X); + var _super = _createSuper(A); function A() { _classCallCheck(this, A); - return _possibleConstructorReturn(this, _getPrototypeOf(A).apply(this, arguments)); + return _super.apply(this, arguments); } return A; }(X); var B = /*#__PURE__*/ function(X) { "use strict"; _inherits(B, X); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(X); diff --git a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.2.minified/output.js index e5a345d80db..9f352f79ce1 100644 --- a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, X1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var X1 = function() { "use strict"; _classCallCheck(this, X1); }, A = function(X) { "use strict"; + _inherits(A, X); + var _super = _createSuper(A); function A() { - return _classCallCheck(this, A), _possibleConstructorReturn(this, _getPrototypeOf(A).apply(this, arguments)); + return _classCallCheck(this, A), _super.apply(this, arguments); } - return _inherits(A, X), A; + return A; }(X1), B = function(X) { "use strict"; + _inherits(B, X); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, X), B; + return B; }(X1); diff --git a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.1.normal/output.js index 8d188ae9725..36cf352fd63 100644 --- a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var X = function X() { "use strict"; _classCallCheck(this, X); @@ -51,18 +76,20 @@ var X = function X() { var A = /*#__PURE__*/ function(X) { "use strict"; _inherits(A, X); + var _super = _createSuper(A); function A() { _classCallCheck(this, A); - return _possibleConstructorReturn(this, _getPrototypeOf(A).apply(this, arguments)); + return _super.apply(this, arguments); } return A; }(X); var B = /*#__PURE__*/ function(X) { "use strict"; _inherits(B, X); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(X); diff --git a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.2.minified/output.js index e5a345d80db..9f352f79ce1 100644 --- a/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, X1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var X1 = function() { "use strict"; _classCallCheck(this, X1); }, A = function(X) { "use strict"; + _inherits(A, X); + var _super = _createSuper(A); function A() { - return _classCallCheck(this, A), _possibleConstructorReturn(this, _getPrototypeOf(A).apply(this, arguments)); + return _classCallCheck(this, A), _super.apply(this, arguments); } - return _inherits(A, X), A; + return A; }(X1), B = function(X) { "use strict"; + _inherits(B, X); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, X), B; + return B; }(X1); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.1.normal/output.js index e713c16a08e..76d4748aa7a 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -51,18 +76,20 @@ var Base = function Base() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.2.minified/output.js index bc54082067a..e0c817c082b 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/generatedContextualTyping/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x193, x194, x195, x196, x197, x198, x199, x200, x201, x202, x203, x204, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x193, x194, x195, x196, x197, x198, x199, x200, x201, x202, x203, x204, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); new Base1(); var d1 = new Derived1(), d2 = new Derived2(), x13 = function() { diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.1.normal/output.js index 0c2de5dca68..c428fa1c81d 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A(map) { "use strict"; _classCallCheck(this, A); @@ -52,11 +77,12 @@ var A = function A(map) { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).call(this, function(value) { + return _super.call(this, function(value) { return String(value.toExponential()); - })); + }); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.2.minified/output.js index 763c22fee20..ce42df9f719 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping1/input.ts/es5.2.minified/output.js @@ -16,16 +16,7 @@ var A1 = function(map) { _classCallCheck(this, A1), this.map = map; }, B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, (call = _getPrototypeOf(B).call(this, function(value) { - return String(value.toExponential()); - })) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,5 +25,35 @@ var A1 = function(map) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.call(this, function(value) { + return String(value.toExponential()); + }); + } + return B; }(A1); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.1.normal/output.js index 2ff552cb670..1580a68cd14 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A(map) { "use strict"; _classCallCheck(this, A); @@ -52,11 +77,12 @@ var A = function A(map) { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).call(this, function(value) { + return _super.call(this, function(value) { return String(value()); - })); + }); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.2.minified/output.js index c9a14fadc5d..1c53beb0fa2 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping2/input.ts/es5.2.minified/output.js @@ -16,16 +16,7 @@ var A1 = function(map) { _classCallCheck(this, A1), this.map = map; }, C = function(A) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, (call = _getPrototypeOf(C).call(this, function(value) { - return String(value()); - })) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,5 +25,35 @@ var A1 = function(map) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, A), C; + }(C, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.call(this, function(value) { + return String(value()); + }); + } + return C; }(A1); diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.1.normal/output.js index b28138246ea..9da9464e0bc 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var CBase = /*#__PURE__*/ function() { "use strict"; function CBase(param) { @@ -98,16 +123,18 @@ var CBase = /*#__PURE__*/ function() { var C = /*#__PURE__*/ function(CBase) { "use strict"; _inherits(C, CBase); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this, { + var _thisSuper; + var _this = _super.call(this, { method: function(p) { p.length; } - })); + }); // Should be okay. // 'p' should have type 'string'. - _get(_getPrototypeOf(C.prototype), "foo", _assertThisInitialized(_this)).call(_this, { + _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(C.prototype)), "foo", _thisSuper).call(_thisSuper, { method: function(p) { p.length; } diff --git a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.2.minified/output.js index 382c5ee3964..2979724d8b2 100644 --- a/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/contextualTyping/superCallParameterContextualTyping3/input.ts/es5.2.minified/output.js @@ -49,20 +49,7 @@ var CBase = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), CBase; }(), C = function(CBase) { "use strict"; - function C() { - _classCallCheck(this, C); - var obj, self, call, _this = (self = this, (call = _getPrototypeOf(C).call(this, { - method: function(p) { - p.length; - } - })) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self)); - return _get(_getPrototypeOf(C.prototype), "foo", _assertThisInitialized(_this)).call(_this, { - method: function(p) { - p.length; - } - }), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -71,5 +58,40 @@ var CBase = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, CBase), C; + }(C, CBase); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(C); + function C() { + _classCallCheck(this, C); + var _thisSuper, _this = _super.call(this, { + method: function(p) { + p.length; + } + }); + return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(C.prototype)), "foo", _thisSuper).call(_thisSuper, { + method: function(p) { + p.length; + } + }), _this; + } + return C; }(CBase); diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.1.normal/output.js index a0ababbd0c8..da226477b7b 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.1.normal/output.js @@ -98,6 +98,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _obj, _obj1, _obj2, _obj3, _instance4, _obj4, _instance1, _instance2, _instance3; function foo(x, y) { for(var _len = arguments.length, z = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){ @@ -225,15 +250,15 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { - var _instance; _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, 1, 2)); - return _possibleConstructorReturn(this, (_instance = _getPrototypeOf(D)).call.apply(_instance, [ + return _super.call(this, 1, 2); + return _super.call.apply(_super, [ this, 1, 2 - ].concat(_toConsumableArray(a)))); + ].concat(_toConsumableArray(a))); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.2.minified/output.js index 9a33d9641e5..c029a0d2975 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpread/input.ts/es5.2.minified/output.js @@ -138,14 +138,7 @@ var _obj, _obj1, _obj2, _obj3, _instance4, _obj4, _instance1, _instance2, _insta ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, (call = _getPrototypeOf(D).call(this, 1, 2)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -154,7 +147,35 @@ var _obj, _obj1, _obj2, _obj3, _instance4, _obj4, _instance1, _instance2, _insta configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.call(this, 1, 2); + } + return _createClass(D, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.1.normal/output.js index 69fb79c4501..97a70123f8b 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.1.normal/output.js @@ -98,6 +98,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _obj, _obj1, _instance2, _instance1; function foo(x, y) { for(var _len = arguments.length, z = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){ @@ -185,15 +210,15 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { - var _instance; _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).call(this, 1, 2)); - return _possibleConstructorReturn(this, (_instance = _getPrototypeOf(D)).call.apply(_instance, [ + return _super.call(this, 1, 2); + return _super.call.apply(_super, [ this, 1, 2 - ].concat(_toConsumableArray(a)))); + ].concat(_toConsumableArray(a))); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.2.minified/output.js index 24133ebc3f0..951e51488f0 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/callWithSpreadES6/input.ts/es5.2.minified/output.js @@ -104,14 +104,7 @@ var _obj, _obj1, _instance2, _instance1, a, obj1, xa, C = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, (call = _getPrototypeOf(D).call(this, 1, 2)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -120,7 +113,35 @@ var _obj, _obj1, _instance2, _instance1, a, obj1, xa, C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.call(this, 1, 2); + } + return _createClass(D, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.1.normal/output.js index a6d0329e554..2d0f8525e3c 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var SomeBase = function SomeBase() { "use strict"; _classCallCheck(this, SomeBase); @@ -51,27 +76,30 @@ var SomeBase = function SomeBase() { var SomeDerived1 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { _classCallCheck(this, SomeDerived1); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived1; }(SomeBase); var SomeDerived2 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { _classCallCheck(this, SomeDerived2); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived2; }(SomeBase); var SomeDerived3 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { _classCallCheck(this, SomeDerived3); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived3; }(SomeBase); diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.2.minified/output.js index 209762e2546..5d29b95530b 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolution/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, SomeBase1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var SomeBase1 = function() { "use strict"; _classCallCheck(this, SomeBase1); }, SomeDerived1 = function(SomeBase) { "use strict"; + _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { - return _classCallCheck(this, SomeDerived1), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _classCallCheck(this, SomeDerived1), _super.apply(this, arguments); } - return _inherits(SomeDerived1, SomeBase), SomeDerived1; + return SomeDerived1; }(SomeBase1), SomeDerived2 = function(SomeBase) { "use strict"; + _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { - return _classCallCheck(this, SomeDerived2), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _classCallCheck(this, SomeDerived2), _super.apply(this, arguments); } - return _inherits(SomeDerived2, SomeBase), SomeDerived2; + return SomeDerived2; }(SomeBase1), SomeDerived3 = function(SomeBase) { "use strict"; + _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { - return _classCallCheck(this, SomeDerived3), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _classCallCheck(this, SomeDerived3), _super.apply(this, arguments); } - return _inherits(SomeDerived3, SomeBase), SomeDerived3; + return SomeDerived3; }(SomeBase1); function fn1() { return null; diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.1.normal/output.js index bf95474d49d..46a1a0ee091 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var SomeBase = function SomeBase() { "use strict"; _classCallCheck(this, SomeBase); @@ -51,27 +76,30 @@ var SomeBase = function SomeBase() { var SomeDerived1 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { _classCallCheck(this, SomeDerived1); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived1; }(SomeBase); var SomeDerived2 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { _classCallCheck(this, SomeDerived2); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived2; }(SomeBase); var SomeDerived3 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { _classCallCheck(this, SomeDerived3); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived3; }(SomeBase); diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.2.minified/output.js index bc1b92c78d3..4fe57d1ff5c 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionClassConstructors/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, SomeBase1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var SomeBase1 = function() { "use strict"; _classCallCheck(this, SomeBase1); }, SomeDerived1 = function(SomeBase) { "use strict"; + _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { - return _classCallCheck(this, SomeDerived1), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _classCallCheck(this, SomeDerived1), _super.apply(this, arguments); } - return _inherits(SomeDerived1, SomeBase), SomeDerived1; + return SomeDerived1; }(SomeBase1), SomeDerived2 = function(SomeBase) { "use strict"; + _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { - return _classCallCheck(this, SomeDerived2), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _classCallCheck(this, SomeDerived2), _super.apply(this, arguments); } - return _inherits(SomeDerived2, SomeBase), SomeDerived2; + return SomeDerived2; }(SomeBase1), SomeDerived3 = function(SomeBase) { "use strict"; + _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { - return _classCallCheck(this, SomeDerived3), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _classCallCheck(this, SomeDerived3), _super.apply(this, arguments); } - return _inherits(SomeDerived3, SomeBase), SomeDerived3; + return SomeDerived3; }(SomeBase1), fn1 = function() { "use strict"; _classCallCheck(this, fn1); diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.1.normal/output.js index b677faff051..01f6385af50 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var SomeBase = function SomeBase() { "use strict"; _classCallCheck(this, SomeBase); @@ -51,27 +76,30 @@ var SomeBase = function SomeBase() { var SomeDerived1 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { _classCallCheck(this, SomeDerived1); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived1; }(SomeBase); var SomeDerived2 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { _classCallCheck(this, SomeDerived2); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived2; }(SomeBase); var SomeDerived3 = /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { _classCallCheck(this, SomeDerived3); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _super.apply(this, arguments); } return SomeDerived3; }(SomeBase); diff --git a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.2.minified/output.js index f6c2bd33c64..b56c4eb8150 100644 --- a/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/functionCalls/overloadResolutionConstructors/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var fn1, fn2, fn3, fn4, fn5, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, SomeBase1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var fn1, fn2, fn3, fn4, fn5, SomeBase1 = function() { "use strict"; _classCallCheck(this, SomeBase1); }, SomeDerived1 = function(SomeBase) { "use strict"; + _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { - return _classCallCheck(this, SomeDerived1), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).apply(this, arguments)); + return _classCallCheck(this, SomeDerived1), _super.apply(this, arguments); } - return _inherits(SomeDerived1, SomeBase), SomeDerived1; + return SomeDerived1; }(SomeBase1), SomeDerived2 = function(SomeBase) { "use strict"; + _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { - return _classCallCheck(this, SomeDerived2), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).apply(this, arguments)); + return _classCallCheck(this, SomeDerived2), _super.apply(this, arguments); } - return _inherits(SomeDerived2, SomeBase), SomeDerived2; + return SomeDerived2; }(SomeBase1), SomeDerived3 = function(SomeBase) { "use strict"; + _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { - return _classCallCheck(this, SomeDerived3), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _classCallCheck(this, SomeDerived3), _super.apply(this, arguments); } - return _inherits(SomeDerived3, SomeBase), SomeDerived3; + return SomeDerived3; }(SomeBase1); new fn1(void 0), new fn1({ }), new fn2(0, void 0), new fn2(0, ""), new fn2("", 0), new fn2("", 0), new fn3(3), new fn3("", 3, ""), new fn3(5, 5, 5), new fn3(4), new fn3("", "", ""), new fn3("", "", 3), new fn3(), new fn4("", 3), new fn4(3, ""), new fn4("", 3), new fn4(3, ""), new fn4("", 3), new fn4(3, ""), new fn4(3, void 0), new fn4("", null), new fn4(null, null), new fn4(!0, null), new fn4(null, !0), new fn5(function(n) { diff --git a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.1.normal/output.js index f250b8bab74..ee198b83051 100644 --- a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @target: *,-es3 // @strict: true // @noTypesAndSymbols: true @@ -99,28 +124,29 @@ var Base = // @target: *,-es3 ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "method1", value: function method1() { var ref; - return (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); + return (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); } }, { key: "method2", value: function method2() { var ref; - return (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); + return (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.2.minified/output.js index c1f6e4220c1..ef7af1ada32 100644 --- a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/callChainWithSuper/input.ts/es5.2.minified/output.js @@ -45,16 +45,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -63,20 +56,48 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "method1", value: function() { var ref; - return null === (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); + return null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); } }, { key: "method2", value: function() { var ref; - return null === (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); + return null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.1.normal/output.js index a10582d07d8..6b43cb1a322 100644 --- a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.1.normal/output.js @@ -111,6 +111,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @strict: true // @target: ES6 /*#__PURE__*/ function() { @@ -127,19 +152,20 @@ var Base = // @strict: true ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "method", value: function method() { var ref; - return (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); + return (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) === null || ref === void 0 ? void 0 : ref.call(this); } }, { @@ -147,7 +173,7 @@ var Derived = /*#__PURE__*/ function(Base) { value: function asyncMethod() { var _this = this; var _super_method = function() { - return _get(_getPrototypeOf(Derived.prototype), "method", _this); + return _get(_getPrototypeOf(Derived1.prototype), "method", _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var ref; @@ -165,5 +191,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.2.minified/output.js index e990a03f723..0b54c3a3163 100644 --- a/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/optionalChaining/callChain/superMethodCall/input.ts/es5.2.minified/output.js @@ -55,16 +55,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -73,12 +66,40 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "method", value: function() { var ref; - return null === (ref = _get(_getPrototypeOf(Derived.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); + return null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", this)) || void 0 === ref ? void 0 : ref.call(this); } }, { @@ -104,7 +125,7 @@ var Base = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", null === (ref = _get(_getPrototypeOf(Derived.prototype), "method", _this)) || void 0 === ref ? void 0 : ref.call(this)); + return _ctx.abrupt("return", null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", _this)) || void 0 === ref ? void 0 : ref.call(this)); case 2: case "end": return _ctx.stop(); @@ -113,5 +134,5 @@ var Base = function() { }).bind(this))(); } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.1.normal/output.js index 951c3ac0e0e..1d1f85907ae 100644 --- a/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,9 +76,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.2.minified/output.js index 0c195dca1bd..42ee4dd6284 100644 --- a/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/propertyAccess/propertyAccess/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var Compass, bothIndex, stringOrNumber, someObject, Compass1, A1 = function() { _classCallCheck(this, A1); }, B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Compass, bothIndex, stringOrNumber, someObject, Compass1, A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return B; }(A1); (Compass1 = Compass || (Compass = { }))[Compass1.North = 0] = "North", Compass1[Compass1.South = 1] = "South", Compass1[Compass1.East = 2] = "East", Compass1[Compass1.West = 3] = "West"; diff --git a/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.1.normal/output.js index 7312d0640d0..3396daf4ffd 100644 --- a/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base(n) { "use strict"; _classCallCheck(this, Base); @@ -51,21 +76,22 @@ var Base = function Base(n) { }; function v() { } -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived(q) { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(q) { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, '')); + _this = _super.call(this, ''); _this.q = q; var _temp; //type of super call expression is void - var p = (_temp = _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, '')), _this.q = q, _temp); + var p = (_temp = _this = _super.call(this, ''), _this.q = q, _temp); var p = v(); return _this; } - return Derived; + return Derived1; }(Base); var OtherBase = function OtherBase() { "use strict"; @@ -74,10 +100,11 @@ var OtherBase = function OtherBase() { var OtherDerived = /*#__PURE__*/ function(OtherBase) { "use strict"; _inherits(OtherDerived, OtherBase); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); var p = ''; - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).call(this)); + return _super.call(this); } return OtherDerived; }(OtherBase); diff --git a/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.2.minified/output.js index 5d6eee1594c..83b2df706e4 100644 --- a/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superCalls/superCalls/input.ts/es5.2.minified/output.js @@ -16,36 +16,56 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function(n) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function(n) { "use strict"; _classCallCheck(this, Base1), this.x = 43; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived(q) { + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1(q) { var _this; - return _classCallCheck(this, Derived), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, ""))).q = q, (_this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this, ""))).q = q, _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this, "")).q = q, (_this = _super.call(this, "")).q = q, _this; } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), OtherBase1 = function() { "use strict"; _classCallCheck(this, OtherBase1); }, OtherDerived = function(OtherBase) { "use strict"; + _inherits(OtherDerived, OtherBase); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).call(this)); + return _classCallCheck(this, OtherDerived), _super.call(this); } - return _inherits(OtherDerived, OtherBase), OtherDerived; + return OtherDerived; }(OtherBase1); diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.1.normal/output.js index 816c5b0e5b2..59f240c9f57 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.1.normal/output.js @@ -132,6 +132,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var NoBase = //super property access in constructor of class with no base type //super property access in instance member function of class with no base type //super property access in instance member accessor(get and set) of class with no base type @@ -215,10 +240,12 @@ var SomeDerived1 = //super.publicInstanceMemberNotFunction in constructor of der /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { _classCallCheck(this, SomeDerived1); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).call(this)); - _set(_getPrototypeOf(SomeDerived1.prototype), "publicMember", 1, this, true); + var _thisSuper; + var _this = _super.call(this); + _set((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerived1.prototype)), "publicMember", 1, _thisSuper, true); return _this; } _createClass(SomeDerived1, [ @@ -260,10 +287,12 @@ var SomeDerived2 = //super.privateProperty in constructor of derived class /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { _classCallCheck(this, SomeDerived2); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).call(this)); - _set(_getPrototypeOf(SomeDerived2.prototype), "privateMember", 1, this, true); + var _thisSuper; + var _this = _super.call(this); + _set((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerived2.prototype)), "privateMember", 1, _thisSuper, true); return _this; } _createClass(SomeDerived2, [ @@ -293,9 +322,10 @@ var SomeDerived3 = //super.publicStaticMemberNotFunction in static member functi /*#__PURE__*/ function(SomeBase) { "use strict"; _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { _classCallCheck(this, SomeDerived3); - return _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(SomeDerived3, null, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.2.minified/output.js index f1587e31bfd..e9bcb5d1432 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/errorSuperPropertyAccess/input.ts/es5.2.minified/output.js @@ -1,3 +1,7 @@ +function _assertThisInitialized(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; +} function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -34,12 +38,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function set(target, property, value, receiver) { return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function set(target, property, value, receiver) { var obj, key, value, desc, base = _superPropBase(target, property); @@ -72,9 +70,28 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, NoBase = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; +} +var NoBase = function() { "use strict"; function NoBase() { _classCallCheck(this, NoBase), this.m = _get(_getPrototypeOf(NoBase.prototype), "prototype", this), this.n = _get(_getPrototypeOf(NoBase.prototype), "hasOwnProperty", this).call(this, ""), _get(_getPrototypeOf(NoBase.prototype), "prototype", this), _get(_getPrototypeOf(NoBase.prototype), "hasOwnProperty", this).call(this, ""); @@ -135,12 +152,14 @@ var _typeof = function(obj) { SomeBase.privateStaticMember = 0, SomeBase.publicStaticMember = 0; var SomeDerived1 = function(SomeBase) { "use strict"; + _inherits(SomeDerived1, SomeBase); + var _super = _createSuper(SomeDerived1); function SomeDerived1() { _classCallCheck(this, SomeDerived1); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived1).call(this)); - return _set(_getPrototypeOf(SomeDerived1.prototype), "publicMember", 1, this, !0), _this; + var _thisSuper, _this = _super.call(this); + return _set((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerived1.prototype)), "publicMember", 1, _thisSuper, !0), _this; } - return _inherits(SomeDerived1, SomeBase), _createClass(SomeDerived1, [ + return _createClass(SomeDerived1, [ { key: "fn", value: function() { @@ -164,12 +183,14 @@ var SomeDerived1 = function(SomeBase) { ]), SomeDerived1; }(SomeBase), SomeDerived2 = function(SomeBase) { "use strict"; + _inherits(SomeDerived2, SomeBase); + var _super = _createSuper(SomeDerived2); function SomeDerived2() { _classCallCheck(this, SomeDerived2); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived2).call(this)); - return _set(_getPrototypeOf(SomeDerived2.prototype), "privateMember", 1, this, !0), _this; + var _thisSuper, _this = _super.call(this); + return _set((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerived2.prototype)), "privateMember", 1, _thisSuper, !0), _this; } - return _inherits(SomeDerived2, SomeBase), _createClass(SomeDerived2, [ + return _createClass(SomeDerived2, [ { key: "fn", value: function() { @@ -188,10 +209,12 @@ var SomeDerived1 = function(SomeBase) { ]), SomeDerived2; }(SomeBase), SomeDerived3 = function(SomeBase) { "use strict"; + _inherits(SomeDerived3, SomeBase); + var _super = _createSuper(SomeDerived3); function SomeDerived3() { - return _classCallCheck(this, SomeDerived3), _possibleConstructorReturn(this, _getPrototypeOf(SomeDerived3).apply(this, arguments)); + return _classCallCheck(this, SomeDerived3), _super.apply(this, arguments); } - return _inherits(SomeDerived3, SomeBase), _createClass(SomeDerived3, null, [ + return _createClass(SomeDerived3, null, [ { key: "fn", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.1.normal/output.js index a3d05be17c1..abd82230a4a 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var SomeBaseClass = // @target: es5 //super.publicInstanceMemberFunction in constructor of derived class //super.publicInstanceMemberFunction in instance member function of derived class @@ -119,10 +144,12 @@ var SomeBaseClass = // @target: es5 var SomeDerivedClass = /*#__PURE__*/ function(SomeBaseClass) { "use strict"; _inherits(SomeDerivedClass, SomeBaseClass); + var _super = _createSuper(SomeDerivedClass); function SomeDerivedClass() { _classCallCheck(this, SomeDerivedClass); - var _this = _possibleConstructorReturn(this, _getPrototypeOf(SomeDerivedClass).call(this)); - var x = _get(_getPrototypeOf(SomeDerivedClass.prototype), "func", _assertThisInitialized(_this)).call(_this); + var _thisSuper; + var _this = _super.call(this); + var x = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerivedClass.prototype)), "func", _thisSuper).call(_thisSuper); var x; return _this; } diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.2.minified/output.js index de19681b606..6fc3d7db3b4 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superPropertyAccessNoError/input.ts/es5.2.minified/output.js @@ -65,12 +65,7 @@ var SomeBaseClass = function() { ]), SomeBaseClass; }(), SomeDerivedClass = function(SomeBaseClass) { "use strict"; - function SomeDerivedClass() { - _classCallCheck(this, SomeDerivedClass); - var obj, self, call, _this = (self = this, (call = _getPrototypeOf(SomeDerivedClass).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self)); - return _get(_getPrototypeOf(SomeDerivedClass.prototype), "func", _assertThisInitialized(_this)).call(_this), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -79,7 +74,34 @@ var SomeBaseClass = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(SomeDerivedClass, SomeBaseClass), _createClass(SomeDerivedClass, [ + }(SomeDerivedClass, SomeBaseClass); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(SomeDerivedClass); + function SomeDerivedClass() { + _classCallCheck(this, SomeDerivedClass); + var _thisSuper, _this = _super.call(this); + return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SomeDerivedClass.prototype)), "func", _thisSuper).call(_thisSuper), _this; + } + return _createClass(SomeDerivedClass, [ { key: "fn", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.1.normal/output.js index 16c18802ea1..ba417952489 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES6 var symbol = Symbol.for('myThing'); var tmp = symbol; @@ -103,9 +128,10 @@ var tmp1 = symbol; var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Bar, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.2.minified/output.js index fe49058bd75..aa5a8143525 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess1/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var symbol = Symbol.for("myThing"), tmp = symbol, Foo = function() { ]), Foo; }(), tmp1 = symbol, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var symbol = Symbol.for("myThing"), tmp = symbol, Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), _createClass(Bar, [ + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return _createClass(Bar, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.1.normal/output.js index 3529d8f9bb8..c351227b627 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var tmp = Symbol.isConcatSpreadable; var Foo = //@target: ES6 /*#__PURE__*/ function() { @@ -102,9 +127,10 @@ var tmp1 = Symbol.isConcatSpreadable; var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Bar, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.2.minified/output.js index f1d97a32612..9b87815404d 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess2/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var tmp = Symbol.isConcatSpreadable, Foo = function() { ]), Foo; }(), tmp1 = Symbol.isConcatSpreadable, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var tmp = Symbol.isConcatSpreadable, Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), _createClass(Bar, [ + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return _createClass(Bar, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.1.normal/output.js index d73b8851b31..0dba941fbde 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES6 var symbol = Symbol.for('myThing'); var tmp = symbol; @@ -103,9 +128,10 @@ var tmp1 = symbol; var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Bar, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.2.minified/output.js index e2c1186e00d..8f66250879c 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess3/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var symbol = Symbol.for("myThing"), tmp = symbol, Foo = function() { ]), Foo; }(), tmp1 = symbol, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var symbol = Symbol.for("myThing"), tmp = symbol, Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), _createClass(Bar, [ + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return _createClass(Bar, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.1.normal/output.js index d2f9bef59b6..bb5a63f88ba 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES5 var symbol; var tmp = symbol; @@ -103,9 +128,10 @@ var tmp1 = symbol; var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Bar, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.2.minified/output.js index 4f5e2b716b1..529b793e13c 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess5/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var symbol, tmp = symbol, Foo = function() { ]), Foo; }(), tmp1 = symbol, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var symbol, tmp = symbol, Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), _createClass(Bar, [ + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return _createClass(Bar, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.1.normal/output.js index 000f75386ce..acaf3f000f5 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} //@target: ES5 var symbol; var tmp = symbol; @@ -103,9 +128,10 @@ var tmp1 = symbol; var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Bar, null, [ { diff --git a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.2.minified/output.js index c4cf2de82f7..e9285d98071 100644 --- a/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/superPropertyAccess/superSymbolIndexedAccess6/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ var symbol, tmp = symbol, Foo = function() { ]), Foo; }(), tmp1 = symbol, Bar = function(Foo) { "use strict"; - function Bar() { - var self, call, obj; - return _classCallCheck(this, Bar), self = this, call = _getPrototypeOf(Bar).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var symbol, tmp = symbol, Foo = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Bar, Foo), _createClass(Bar, null, [ + }(Bar, Foo); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Bar); + function Bar() { + return _classCallCheck(this, Bar), _super.apply(this, arguments); + } + return _createClass(Bar, null, [ { key: tmp1, value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.1.normal/output.js index 166366b83b8..f546a104709 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -69,9 +94,10 @@ var B = function B() { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.2.minified/output.js index d89869be3f7..9d1d02817d9 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunction/input.ts/es5.2.minified/output.js @@ -25,14 +25,7 @@ var a, subType, union, union2, A1 = function() { _classCallCheck(this, B); }, C = function(A) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -41,7 +34,35 @@ var a, subType, union, union2, A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, A), C; + }(C, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return C; }(A1); isC(a) && a.propC, isA(subType) && subType.propC, isA(union) && union.propA, isC_multipleParams(a, 0) && a.propC; var D = function() { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.1.normal/output.js index bc9789e1014..8a1bbc6d11d 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -55,9 +80,10 @@ var B = function B() { var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.2.minified/output.js index c7b8b13bec0..a2ac5d74f1e 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionGenerics/input.ts/es5.2.minified/output.js @@ -19,14 +19,7 @@ var a, A1 = function() { _classCallCheck(this, B); }, C = function(A) { "use strict"; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,6 +28,34 @@ var a, A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, A), C; + }(C, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return C; }(A1); funA(isB), funB(retC, a) && a.propC, funC(isB), funD(isC, a) && a.propC, funE(isB, 1); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.1.normal/output.js index 165474a8fbd..2276ae0068f 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.1.normal/output.js @@ -65,6 +65,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var RoyalGuard = // @declaration: true /*#__PURE__*/ function() { "use strict"; @@ -90,9 +115,10 @@ var RoyalGuard = // @declaration: true var LeadGuard = /*#__PURE__*/ function(RoyalGuard) { "use strict"; _inherits(LeadGuard, RoyalGuard); + var _super = _createSuper(LeadGuard); function LeadGuard() { _classCallCheck(this, LeadGuard); - return _possibleConstructorReturn(this, _getPrototypeOf(LeadGuard).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(LeadGuard, [ { @@ -106,9 +132,10 @@ var LeadGuard = /*#__PURE__*/ function(RoyalGuard) { var FollowerGuard = /*#__PURE__*/ function(RoyalGuard) { "use strict"; _inherits(FollowerGuard, RoyalGuard); + var _super = _createSuper(FollowerGuard); function FollowerGuard() { _classCallCheck(this, FollowerGuard); - return _possibleConstructorReturn(this, _getPrototypeOf(FollowerGuard).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(FollowerGuard, [ { @@ -165,9 +192,10 @@ var ArrowGuard = function ArrowGuard() { var ArrowElite = /*#__PURE__*/ function(ArrowGuard) { "use strict"; _inherits(ArrowElite, ArrowGuard); + var _super = _createSuper(ArrowElite); function ArrowElite() { _classCallCheck(this, ArrowElite); - return _possibleConstructorReturn(this, _getPrototypeOf(ArrowElite).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(ArrowElite, [ { @@ -181,9 +209,10 @@ var ArrowElite = /*#__PURE__*/ function(ArrowGuard) { var ArrowMedic = /*#__PURE__*/ function(ArrowGuard) { "use strict"; _inherits(ArrowMedic, ArrowGuard); + var _super = _createSuper(ArrowMedic); function ArrowMedic() { _classCallCheck(this, ArrowMedic); - return _possibleConstructorReturn(this, _getPrototypeOf(ArrowMedic).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(ArrowMedic, [ { @@ -233,9 +262,10 @@ var MimicGuard = /*#__PURE__*/ function() { var MimicLeader = /*#__PURE__*/ function(MimicGuard) { "use strict"; _inherits(MimicLeader, MimicGuard); + var _super = _createSuper(MimicLeader); function MimicLeader() { _classCallCheck(this, MimicLeader); - return _possibleConstructorReturn(this, _getPrototypeOf(MimicLeader).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MimicLeader, [ { @@ -249,9 +279,10 @@ var MimicLeader = /*#__PURE__*/ function(MimicGuard) { var MimicFollower = /*#__PURE__*/ function(MimicGuard) { "use strict"; _inherits(MimicFollower, MimicGuard); + var _super = _createSuper(MimicFollower); function MimicFollower() { _classCallCheck(this, MimicFollower); - return _possibleConstructorReturn(this, _getPrototypeOf(MimicFollower).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MimicFollower, [ { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.2.minified/output.js index 007fb753419..9132d54acb8 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThis/input.ts/es5.2.minified/output.js @@ -28,20 +28,36 @@ function _inherits(subClass, superClass) { function _instanceof(left, right) { return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, crate, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, RoyalGuard = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, crate, RoyalGuard = function() { "use strict"; function RoyalGuard() { _classCallCheck(this, RoyalGuard); @@ -62,10 +78,12 @@ var b, crate, _typeof = function(obj) { ]), RoyalGuard; }(), LeadGuard = function(RoyalGuard) { "use strict"; + _inherits(LeadGuard, RoyalGuard); + var _super = _createSuper(LeadGuard); function LeadGuard() { - return _classCallCheck(this, LeadGuard), _possibleConstructorReturn(this, _getPrototypeOf(LeadGuard).apply(this, arguments)); + return _classCallCheck(this, LeadGuard), _super.apply(this, arguments); } - return _inherits(LeadGuard, RoyalGuard), _createClass(LeadGuard, [ + return _createClass(LeadGuard, [ { key: "lead", value: function() { @@ -74,10 +92,12 @@ var b, crate, _typeof = function(obj) { ]), LeadGuard; }(RoyalGuard), FollowerGuard = function(RoyalGuard) { "use strict"; + _inherits(FollowerGuard, RoyalGuard); + var _super = _createSuper(FollowerGuard); function FollowerGuard() { - return _classCallCheck(this, FollowerGuard), _possibleConstructorReturn(this, _getPrototypeOf(FollowerGuard).apply(this, arguments)); + return _classCallCheck(this, FollowerGuard), _super.apply(this, arguments); } - return _inherits(FollowerGuard, RoyalGuard), _createClass(FollowerGuard, [ + return _createClass(FollowerGuard, [ { key: "follow", value: function() { @@ -100,10 +120,12 @@ var ArrowGuard1 = function() { }; }, ArrowElite = function(ArrowGuard) { "use strict"; + _inherits(ArrowElite, ArrowGuard); + var _super = _createSuper(ArrowElite); function ArrowElite() { - return _classCallCheck(this, ArrowElite), _possibleConstructorReturn(this, _getPrototypeOf(ArrowElite).apply(this, arguments)); + return _classCallCheck(this, ArrowElite), _super.apply(this, arguments); } - return _inherits(ArrowElite, ArrowGuard), _createClass(ArrowElite, [ + return _createClass(ArrowElite, [ { key: "defend", value: function() { @@ -112,10 +134,12 @@ var ArrowGuard1 = function() { ]), ArrowElite; }(ArrowGuard1), ArrowMedic = function(ArrowGuard) { "use strict"; + _inherits(ArrowMedic, ArrowGuard); + var _super = _createSuper(ArrowMedic); function ArrowMedic() { - return _classCallCheck(this, ArrowMedic), _possibleConstructorReturn(this, _getPrototypeOf(ArrowMedic).apply(this, arguments)); + return _classCallCheck(this, ArrowMedic), _super.apply(this, arguments); } - return _inherits(ArrowMedic, ArrowGuard), _createClass(ArrowMedic, [ + return _createClass(ArrowMedic, [ { key: "heal", value: function() { @@ -145,10 +169,12 @@ var MimicGuard = function() { ]), MimicGuard; }(), MimicLeader = function(MimicGuard) { "use strict"; + _inherits(MimicLeader, MimicGuard); + var _super = _createSuper(MimicLeader); function MimicLeader() { - return _classCallCheck(this, MimicLeader), _possibleConstructorReturn(this, _getPrototypeOf(MimicLeader).apply(this, arguments)); + return _classCallCheck(this, MimicLeader), _super.apply(this, arguments); } - return _inherits(MimicLeader, MimicGuard), _createClass(MimicLeader, [ + return _createClass(MimicLeader, [ { key: "lead", value: function() { @@ -157,10 +183,12 @@ var MimicGuard = function() { ]), MimicLeader; }(MimicGuard), MimicFollower = function(MimicGuard) { "use strict"; + _inherits(MimicFollower, MimicGuard); + var _super = _createSuper(MimicFollower); function MimicFollower() { - return _classCallCheck(this, MimicFollower), _possibleConstructorReturn(this, _getPrototypeOf(MimicFollower).apply(this, arguments)); + return _classCallCheck(this, MimicFollower), _super.apply(this, arguments); } - return _inherits(MimicFollower, MimicGuard), _createClass(MimicFollower, [ + return _createClass(MimicFollower, [ { key: "follow", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.1.normal/output.js index cda7509c715..48b431317b3 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.1.normal/output.js @@ -65,6 +65,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var RoyalGuard = // @declaration: true /*#__PURE__*/ function() { "use strict"; @@ -90,9 +115,10 @@ var RoyalGuard = // @declaration: true var LeadGuard = /*#__PURE__*/ function(RoyalGuard) { "use strict"; _inherits(LeadGuard, RoyalGuard); + var _super = _createSuper(LeadGuard); function LeadGuard() { _classCallCheck(this, LeadGuard); - return _possibleConstructorReturn(this, _getPrototypeOf(LeadGuard).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(LeadGuard, [ { @@ -106,9 +132,10 @@ var LeadGuard = /*#__PURE__*/ function(RoyalGuard) { var FollowerGuard = /*#__PURE__*/ function(RoyalGuard) { "use strict"; _inherits(FollowerGuard, RoyalGuard); + var _super = _createSuper(FollowerGuard); function FollowerGuard() { _classCallCheck(this, FollowerGuard); - return _possibleConstructorReturn(this, _getPrototypeOf(FollowerGuard).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(FollowerGuard, [ { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.2.minified/output.js index a8c197449cd..cf751afdb58 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardFunctionOfFormThisErrors/input.ts/es5.2.minified/output.js @@ -28,20 +28,36 @@ function _inherits(subClass, superClass) { function _instanceof(left, right) { return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var c, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, RoyalGuard = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var c, RoyalGuard = function() { "use strict"; function RoyalGuard() { _classCallCheck(this, RoyalGuard); @@ -62,10 +78,12 @@ var c, _typeof = function(obj) { ]), RoyalGuard; }(), LeadGuard = function(RoyalGuard) { "use strict"; + _inherits(LeadGuard, RoyalGuard); + var _super = _createSuper(LeadGuard); function LeadGuard() { - return _classCallCheck(this, LeadGuard), _possibleConstructorReturn(this, _getPrototypeOf(LeadGuard).apply(this, arguments)); + return _classCallCheck(this, LeadGuard), _super.apply(this, arguments); } - return _inherits(LeadGuard, RoyalGuard), _createClass(LeadGuard, [ + return _createClass(LeadGuard, [ { key: "lead", value: function() { @@ -74,10 +92,12 @@ var c, _typeof = function(obj) { ]), LeadGuard; }(RoyalGuard), FollowerGuard = function(RoyalGuard) { "use strict"; + _inherits(FollowerGuard, RoyalGuard); + var _super = _createSuper(FollowerGuard); function FollowerGuard() { - return _classCallCheck(this, FollowerGuard), _possibleConstructorReturn(this, _getPrototypeOf(FollowerGuard).apply(this, arguments)); + return _classCallCheck(this, FollowerGuard), _super.apply(this, arguments); } - return _inherits(FollowerGuard, RoyalGuard), _createClass(FollowerGuard, [ + return _createClass(FollowerGuard, [ { key: "follow", value: function() { diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.1.normal/output.js index 254449a7431..ec13e2eb8c6 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.1.normal/output.js @@ -51,6 +51,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = function C1() { "use strict"; _classCallCheck(this, C1); @@ -62,9 +87,10 @@ var C2 = function C2() { var D1 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(D1, C1); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(C1); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.2.minified/output.js index 949be349f2a..51eac336d38 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormInstanceOf/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var ctor1, ctor2, ctor3, ctor4, ctor5, ctor6, C11 = function() { _classCallCheck(this, C2); }, D1 = function(C1) { "use strict"; - function D1() { - var self, call, obj; - return _classCallCheck(this, D1), self = this, call = _getPrototypeOf(D1).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var ctor1, ctor2, ctor3, ctor4, ctor5, ctor6, C11 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D1, C1), D1; + }(D1, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D1); + function D1() { + return _classCallCheck(this, D1), _super.apply(this, arguments); + } + return D1; }(C11), C3 = function() { "use strict"; _classCallCheck(this, C3); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.1.normal/output.js index d4f5c6f444c..8c6807a81d1 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = function C1() { "use strict"; _classCallCheck(this, C1); @@ -55,9 +80,10 @@ var C2 = function C2() { var D1 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(D1, C1); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(C1); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.2.minified/output.js index 950483cc276..3b3438533ac 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardOfFormIsType/input.ts/es5.2.minified/output.js @@ -19,14 +19,7 @@ var c1Orc2, c2Ord1, C11 = function() { _classCallCheck(this, C2); }, D1 = function(C1) { "use strict"; - function D1() { - var self, call, obj; - return _classCallCheck(this, D1), self = this, call = _getPrototypeOf(D1).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +28,35 @@ var c1Orc2, c2Ord1, C11 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D1, C1), D1; + }(D1, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D1); + function D1() { + return _classCallCheck(this, D1), _super.apply(this, arguments); + } + return D1; }(C11); function isC1(x) { return !0; diff --git a/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.1.normal/output.js index 59c74ac3b8b..0e99d83fdb6 100644 --- a/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var x = function x() { "use strict"; _classCallCheck(this, x); @@ -59,9 +84,10 @@ var foo2 = require('./foo2'); var x = /*#__PURE__*/ function(_x) { "use strict"; _inherits(x, _x); + var _super = _createSuper(x); function x() { _classCallCheck(this, x); - return _possibleConstructorReturn(this, _getPrototypeOf(x).apply(this, arguments)); + return _super.apply(this, arguments); } return x; }(foo2.x); diff --git a/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.2.minified/output.js index 64aedcb3364..d9f657495db 100644 --- a/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/externalModules/reexportClassDefinition/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ module.exports = { }; var x = function(_x) { "use strict"; - function x() { - var self, call, obj; - return _classCallCheck(this, x), self = this, call = _getPrototypeOf(x).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,6 +31,34 @@ var x = function(_x) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(x, _x), x; + }(x, _x); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(x); + function x() { + return _classCallCheck(this, x), _super.apply(this, arguments); + } + return x; }(require("./foo2").x); export { }; diff --git a/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.1.normal/output.js index e7d4cfca9cc..36ff139cab5 100644 --- a/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @allowUnreachableCode: true // FunctionExpression with no return type annotation with multiple return statements with unrelated types var f1 = function f1() { @@ -100,18 +125,20 @@ var AnotherClass = function AnotherClass() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.2.minified/output.js index c15e573caa3..ec69e082346 100644 --- a/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/functions/functionImplementationErrors/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, AnotherClass = function() { @@ -37,14 +53,18 @@ var _typeof = function(obj) { _classCallCheck(this, AnotherClass); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.1.normal/output.js index 7d987c21299..e4219b2c5ed 100644 --- a/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @allowUnreachableCode: true // FunctionExpression with no return type annotation and no return statement returns void var v = function() { @@ -110,24 +135,25 @@ var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var b; var b = function() { return new Base(); - return new Derived(); + return new Derived1(); }(); // FunctionExpression with no return type annotation with multiple return statements with one a recursive call var a = function f() { return new Base(); - return new Derived(); + return new Derived1(); return f(); // ? }(); // FunctionExpression with non -void return type annotation with a single throw statement @@ -169,9 +195,10 @@ function f6() { var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); @@ -194,11 +221,11 @@ var f8 = function(x) { }; var f9 = function(x) { return new Base(); - return new Derived(); + return new Derived1(); return new Derived2(); }; var f10 = function(x) { - return new Derived(); + return new Derived1(); return new Derived2(); }; var f11 = function(x) { diff --git a/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.2.minified/output.js index 30843915462..0a44ee07fd0 100644 --- a/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/functions/functionImplementations/input.ts/es5.2.minified/output.js @@ -16,20 +16,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function rec1() { return rec2(); } @@ -46,20 +61,24 @@ rec1(), rec2(), rec3(), rec4(); var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1); new Base1(), new Base1(); var Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1), AnotherClass = function() { "use strict"; _classCallCheck(this, AnotherClass); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.1.normal/output.js index df045b75f3e..be2f0d8cd62 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var BaseClass = function BaseClass() { "use strict"; _classCallCheck(this, BaseClass); @@ -51,9 +76,10 @@ var BaseClass = function BaseClass() { var Broken = /*#__PURE__*/ function(BaseClass) { "use strict"; _inherits(Broken, BaseClass); + var _super = _createSuper(Broken); function Broken() { _classCallCheck(this, Broken); - return _possibleConstructorReturn(this, _getPrototypeOf(Broken).apply(this, arguments)); + return _super.apply(this, arguments); } return Broken; }(BaseClass); @@ -61,9 +87,10 @@ new Broken().bar; var IncorrectlyExtends = /*#__PURE__*/ function(BaseClass) { "use strict"; _inherits(IncorrectlyExtends, BaseClass); + var _super = _createSuper(IncorrectlyExtends); function IncorrectlyExtends() { _classCallCheck(this, IncorrectlyExtends); - return _possibleConstructorReturn(this, _getPrototypeOf(IncorrectlyExtends).apply(this, arguments)); + return _super.apply(this, arguments); } return IncorrectlyExtends; }(BaseClass); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.2.minified/output.js index d12b63ea415..84c49cd5fb6 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInheritedMembersSatisfyAbstractBase/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, BaseClass1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var BaseClass1 = function() { "use strict"; _classCallCheck(this, BaseClass1); }, Broken = function(BaseClass) { "use strict"; + _inherits(Broken, BaseClass); + var _super = _createSuper(Broken); function Broken() { - return _classCallCheck(this, Broken), _possibleConstructorReturn(this, _getPrototypeOf(Broken).apply(this, arguments)); + return _classCallCheck(this, Broken), _super.apply(this, arguments); } - return _inherits(Broken, BaseClass), Broken; + return Broken; }(BaseClass1); new Broken().bar; var IncorrectlyExtends = function(BaseClass) { "use strict"; + _inherits(IncorrectlyExtends, BaseClass); + var _super = _createSuper(IncorrectlyExtends); function IncorrectlyExtends() { - return _classCallCheck(this, IncorrectlyExtends), _possibleConstructorReturn(this, _getPrototypeOf(IncorrectlyExtends).apply(this, arguments)); + return _classCallCheck(this, IncorrectlyExtends), _super.apply(this, arguments); } - return _inherits(IncorrectlyExtends, BaseClass), IncorrectlyExtends; + return IncorrectlyExtends; }(BaseClass1); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.1.normal/output.js index fc04143f4f9..b58d033696d 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -55,18 +80,20 @@ var C2 = function C2() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); var E = /*#__PURE__*/ function(C2) { "use strict"; _inherits(E, C2); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } return E; }(C2); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.2.minified/output.js index 611c02f125a..49b9277ea3d 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var a, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var a, C1 = function() { "use strict"; _classCallCheck(this, C1); }, C21 = function() { @@ -37,15 +53,19 @@ var a, _typeof = function(obj) { _classCallCheck(this, C21); }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C1), E = function(C2) { "use strict"; + _inherits(E, C2); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, C2), E; + return E; }(C21); a.x, a.w; diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.1.normal/output.js index 8eff7b25d02..0e928b64942 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -55,9 +80,10 @@ var C2 = function C2() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.2.minified/output.js index 87be12ebb36..bc443ddb546 100644 --- a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates3/input.ts/es5.2.minified/output.js @@ -19,14 +19,7 @@ var M, C1 = function() { _classCallCheck(this, C21); }, D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +28,35 @@ var M, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); !function(M) { var C = function() { diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.1.normal/output.js index fc03d38dde1..e4ea860017d 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.1.normal/output.js @@ -44,66 +44,98 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C1, _super); + var _super1 = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super1.apply(this, arguments); } return C1; }(Constructor()); var C2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C2, _super); + var _super2 = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super2.apply(this, arguments); } return C2; }(Constructor()); var C3 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C3, _super); + var _super3 = _createSuper(C3); function C3() { _classCallCheck(this, C3); - return _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _super3.apply(this, arguments); } return C3; }(Constructor()); var C4 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C4, _super); + var _super4 = _createSuper(C4); function C4() { _classCallCheck(this, C4); - return _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _super4.apply(this, arguments); } return C4; }(Constructor()); var C5 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C5, _super); + var _super5 = _createSuper(C5); function C5() { _classCallCheck(this, C5); - return _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _super5.apply(this, arguments); } return C5; }(Constructor()); var C6 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C6, _super); + var _super6 = _createSuper(C6); function C6() { _classCallCheck(this, C6); - return _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _super6.apply(this, arguments); } return C6; }(Constructor()); var C7 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C7, _super); + var _super7 = _createSuper(C7); function C7() { _classCallCheck(this, C7); - return _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _super7.apply(this, arguments); } return C7; }(Constructor()); @@ -117,36 +149,40 @@ var EX1; var C20 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C20, _super); + var _super8 = _createSuper(C20); function C20() { _classCallCheck(this, C20); - return _possibleConstructorReturn(this, _getPrototypeOf(C20).apply(this, arguments)); + return _super8.apply(this, arguments); } return C20; }(Constructor()); var C21 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C21, _super); + var _super9 = _createSuper(C21); function C21() { _classCallCheck(this, C21); - return _possibleConstructorReturn(this, _getPrototypeOf(C21).apply(this, arguments)); + return _super9.apply(this, arguments); } return C21; }(Constructor()); var C22 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C22, _super); + var _super10 = _createSuper(C22); function C22() { _classCallCheck(this, C22); - return _possibleConstructorReturn(this, _getPrototypeOf(C22).apply(this, arguments)); + return _super10.apply(this, arguments); } return C22; }(Constructor()); var C23 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C23, _super); + var _super11 = _createSuper(C23); function C23() { _classCallCheck(this, C23); - return _possibleConstructorReturn(this, _getPrototypeOf(C23).apply(this, arguments)); + return _super11.apply(this, arguments); } return C23; }(Constructor()); diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.2.minified/output.js index 6af21483865..ac863e5db3a 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection/input.ts/es5.2.minified/output.js @@ -16,86 +16,124 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var EX, EX1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function(_super) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var EX, EX1, C1 = function(_super) { "use strict"; + _inherits(C1, _super); + var _super1 = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super1.apply(this, arguments); } - return _inherits(C1, _super), C1; + return C1; }(Constructor()), C2 = function(_super) { "use strict"; + _inherits(C2, _super); + var _super2 = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super2.apply(this, arguments); } - return _inherits(C2, _super), C2; + return C2; }(Constructor()), C3 = function(_super) { "use strict"; + _inherits(C3, _super); + var _super3 = _createSuper(C3); function C3() { - return _classCallCheck(this, C3), _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _classCallCheck(this, C3), _super3.apply(this, arguments); } - return _inherits(C3, _super), C3; + return C3; }(Constructor()), C4 = function(_super) { "use strict"; + _inherits(C4, _super); + var _super4 = _createSuper(C4); function C4() { - return _classCallCheck(this, C4), _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _classCallCheck(this, C4), _super4.apply(this, arguments); } - return _inherits(C4, _super), C4; + return C4; }(Constructor()), C5 = function(_super) { "use strict"; + _inherits(C5, _super); + var _super5 = _createSuper(C5); function C5() { - return _classCallCheck(this, C5), _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _classCallCheck(this, C5), _super5.apply(this, arguments); } - return _inherits(C5, _super), C5; + return C5; }(Constructor()), C6 = function(_super) { "use strict"; + _inherits(C6, _super); + var _super6 = _createSuper(C6); function C6() { - return _classCallCheck(this, C6), _possibleConstructorReturn(this, _getPrototypeOf(C6).apply(this, arguments)); + return _classCallCheck(this, C6), _super6.apply(this, arguments); } - return _inherits(C6, _super), C6; + return C6; }(Constructor()), C7 = function(_super) { "use strict"; + _inherits(C7, _super); + var _super7 = _createSuper(C7); function C7() { - return _classCallCheck(this, C7), _possibleConstructorReturn(this, _getPrototypeOf(C7).apply(this, arguments)); + return _classCallCheck(this, C7), _super7.apply(this, arguments); } - return _inherits(C7, _super), C7; + return C7; }(Constructor()); (EX1 = EX || (EX = { }))[EX1.A = 0] = "A", EX1[EX1.B = 1] = "B", EX1[EX1.C = 2] = "C"; var C20 = function(_super) { "use strict"; + _inherits(C20, _super); + var _super8 = _createSuper(C20); function C20() { - return _classCallCheck(this, C20), _possibleConstructorReturn(this, _getPrototypeOf(C20).apply(this, arguments)); + return _classCallCheck(this, C20), _super8.apply(this, arguments); } - return _inherits(C20, _super), C20; + return C20; }(Constructor()), C21 = function(_super) { "use strict"; + _inherits(C21, _super); + var _super9 = _createSuper(C21); function C21() { - return _classCallCheck(this, C21), _possibleConstructorReturn(this, _getPrototypeOf(C21).apply(this, arguments)); + return _classCallCheck(this, C21), _super9.apply(this, arguments); } - return _inherits(C21, _super), C21; + return C21; }(Constructor()), C22 = function(_super) { "use strict"; + _inherits(C22, _super); + var _super10 = _createSuper(C22); function C22() { - return _classCallCheck(this, C22), _possibleConstructorReturn(this, _getPrototypeOf(C22).apply(this, arguments)); + return _classCallCheck(this, C22), _super10.apply(this, arguments); } - return _inherits(C22, _super), C22; + return C22; }(Constructor()), C23 = function(_super) { "use strict"; + _inherits(C23, _super); + var _super11 = _createSuper(C23); function C23() { - return _classCallCheck(this, C23), _possibleConstructorReturn(this, _getPrototypeOf(C23).apply(this, arguments)); + return _classCallCheck(this, C23), _super11.apply(this, arguments); } - return _inherits(C23, _super), C23; + return C23; }(Constructor()); diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.1.normal/output.js index ca5eb608c09..2a6034b2566 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.1.normal/output.js @@ -44,48 +44,78 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C1, _super); + var _super1 = _createSuper(C1); function C1() { _classCallCheck(this, C1); - return _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _super1.apply(this, arguments); } return C1; }(Constructor()); var C2 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C2, _super); + var _super2 = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super2.apply(this, arguments); } return C2; }(Constructor()); var C3 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C3, _super); + var _super3 = _createSuper(C3); function C3() { _classCallCheck(this, C3); - return _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _super3.apply(this, arguments); } return C3; }(Constructor()); var C4 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C4, _super); + var _super4 = _createSuper(C4); function C4() { _classCallCheck(this, C4); - return _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _super4.apply(this, arguments); } return C4; }(Constructor()); var C5 = /*#__PURE__*/ function(_super) { "use strict"; _inherits(C5, _super); + var _super5 = _createSuper(C5); function C5() { _classCallCheck(this, C5); - return _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _super5.apply(this, arguments); } return C5; }(Constructor()); diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.2.minified/output.js index 08d97ea8763..a41cc75e73a 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors/input.ts/es5.2.minified/output.js @@ -16,49 +16,75 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var EX, EX1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function(_super) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var EX, EX1, C1 = function(_super) { "use strict"; + _inherits(C1, _super); + var _super1 = _createSuper(C1); function C1() { - return _classCallCheck(this, C1), _possibleConstructorReturn(this, _getPrototypeOf(C1).apply(this, arguments)); + return _classCallCheck(this, C1), _super1.apply(this, arguments); } - return _inherits(C1, _super), C1; + return C1; }(Constructor()), C2 = function(_super) { "use strict"; + _inherits(C2, _super); + var _super2 = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super2.apply(this, arguments); } - return _inherits(C2, _super), C2; + return C2; }(Constructor()), C3 = function(_super) { "use strict"; + _inherits(C3, _super); + var _super3 = _createSuper(C3); function C3() { - return _classCallCheck(this, C3), _possibleConstructorReturn(this, _getPrototypeOf(C3).apply(this, arguments)); + return _classCallCheck(this, C3), _super3.apply(this, arguments); } - return _inherits(C3, _super), C3; + return C3; }(Constructor()), C4 = function(_super) { "use strict"; + _inherits(C4, _super); + var _super4 = _createSuper(C4); function C4() { - return _classCallCheck(this, C4), _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _classCallCheck(this, C4), _super4.apply(this, arguments); } - return _inherits(C4, _super), C4; + return C4; }(Constructor()), C5 = function(_super) { "use strict"; + _inherits(C5, _super); + var _super5 = _createSuper(C5); function C5() { - return _classCallCheck(this, C5), _possibleConstructorReturn(this, _getPrototypeOf(C5).apply(this, arguments)); + return _classCallCheck(this, C5), _super5.apply(this, arguments); } - return _inherits(C5, _super), C5; + return C5; }(Constructor()); (EX1 = EX || (EX = { }))[EX1.A = 0] = "A", EX1[EX1.B = 1] = "B", EX1[EX1.C = 2] = "C"; diff --git a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.1.normal/output.js index 4547ab88805..87e6c4a5b86 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -51,27 +76,30 @@ var Foo = function Foo() { var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); var Bar2 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { _classCallCheck(this, Bar2); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar2; }(Foo); var Bar3 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { _classCallCheck(this, Bar3); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar3; }(Foo); @@ -85,36 +113,40 @@ var M; var Baz = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Baz, Foo); + var _super = _createSuper(Baz); function Baz() { _classCallCheck(this, Baz); - return _possibleConstructorReturn(this, _getPrototypeOf(Baz).apply(this, arguments)); + return _super.apply(this, arguments); } return Baz; }(Foo); var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); var Bar2 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { _classCallCheck(this, Bar2); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar2; }(Foo); var Bar3 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { _classCallCheck(this, Bar3); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar3; }(Foo); @@ -130,18 +162,20 @@ var M2; var Baz = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Baz, Foo); + var _super = _createSuper(Baz); function Baz() { _classCallCheck(this, Baz); - return _possibleConstructorReturn(this, _getPrototypeOf(Baz).apply(this, arguments)); + return _super.apply(this, arguments); } return Baz; }(Foo); var Bar = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { _classCallCheck(this, Bar); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar; }(Foo); @@ -152,18 +186,20 @@ var M2; var Bar2 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { _classCallCheck(this, Bar2); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar2; }(Foo); var Bar3 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { _classCallCheck(this, Bar3); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar3; }(Foo); diff --git a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.2.minified/output.js index a4e7ef93f97..c41e0e306bc 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var M, M2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Foo1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var M, M2, Foo1 = function() { "use strict"; _classCallCheck(this, Foo1); }, Bar = function(Foo) { "use strict"; + _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { - return _classCallCheck(this, Bar), _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _classCallCheck(this, Bar), _super.apply(this, arguments); } - return _inherits(Bar, Foo), Bar; + return Bar; }(Foo1), Bar2 = function(Foo) { "use strict"; + _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { - return _classCallCheck(this, Bar2), _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _classCallCheck(this, Bar2), _super.apply(this, arguments); } - return _inherits(Bar2, Foo), Bar2; + return Bar2; }(Foo1), Bar3 = function(Foo) { "use strict"; + _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { - return _classCallCheck(this, Bar3), _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _classCallCheck(this, Bar3), _super.apply(this, arguments); } - return _inherits(Bar3, Foo), Bar3; + return Bar3; }(Foo1); !function(M) { var Foo2 = function() { @@ -57,28 +79,36 @@ var M, M2, _typeof = function(obj) { _classCallCheck(this, Foo2); }, Baz = function(Foo) { "use strict"; + _inherits(Baz, Foo); + var _super = _createSuper(Baz); function Baz() { - return _classCallCheck(this, Baz), _possibleConstructorReturn(this, _getPrototypeOf(Baz).apply(this, arguments)); + return _classCallCheck(this, Baz), _super.apply(this, arguments); } - return _inherits(Baz, Foo), Baz; + return Baz; }(Foo2), Bar = function(Foo) { "use strict"; + _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { - return _classCallCheck(this, Bar), _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _classCallCheck(this, Bar), _super.apply(this, arguments); } - return _inherits(Bar, Foo), Bar; + return Bar; }(Foo2), Bar2 = function(Foo) { "use strict"; + _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { - return _classCallCheck(this, Bar2), _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _classCallCheck(this, Bar2), _super.apply(this, arguments); } - return _inherits(Bar2, Foo), Bar2; + return Bar2; }(Foo2), Bar3 = function(Foo) { "use strict"; + _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { - return _classCallCheck(this, Bar3), _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _classCallCheck(this, Bar3), _super.apply(this, arguments); } - return _inherits(Bar3, Foo), Bar3; + return Bar3; }(Foo2); }(M || (M = { })), (function(M2) { @@ -87,30 +117,38 @@ var M, M2, _typeof = function(obj) { _classCallCheck(this, Foo3); }, Baz = function(Foo) { "use strict"; + _inherits(Baz, Foo); + var _super = _createSuper(Baz); function Baz() { - return _classCallCheck(this, Baz), _possibleConstructorReturn(this, _getPrototypeOf(Baz).apply(this, arguments)); + return _classCallCheck(this, Baz), _super.apply(this, arguments); } - return _inherits(Baz, Foo), Baz; + return Baz; }(Foo3), Bar = function(Foo) { "use strict"; + _inherits(Bar, Foo); + var _super = _createSuper(Bar); function Bar() { - return _classCallCheck(this, Bar), _possibleConstructorReturn(this, _getPrototypeOf(Bar).apply(this, arguments)); + return _classCallCheck(this, Bar), _super.apply(this, arguments); } - return _inherits(Bar, Foo), Bar; + return Bar; }(Foo3); b.z, b.x, b.y; var Bar2 = function(Foo) { "use strict"; + _inherits(Bar2, Foo); + var _super = _createSuper(Bar2); function Bar2() { - return _classCallCheck(this, Bar2), _possibleConstructorReturn(this, _getPrototypeOf(Bar2).apply(this, arguments)); + return _classCallCheck(this, Bar2), _super.apply(this, arguments); } - return _inherits(Bar2, Foo), Bar2; + return Bar2; }(Foo3), Bar3 = function(Foo) { "use strict"; + _inherits(Bar3, Foo); + var _super = _createSuper(Bar3); function Bar3() { - return _classCallCheck(this, Bar3), _possibleConstructorReturn(this, _getPrototypeOf(Bar3).apply(this, arguments)); + return _classCallCheck(this, Bar3), _super.apply(this, arguments); } - return _inherits(Bar3, Foo), Bar3; + return Bar3; }(Foo3); })(M2 || (M2 = { })); diff --git a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.1.normal/output.js index 8a19c3d89ee..d334e1336a9 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -67,36 +92,40 @@ var Bar4 = function Bar4() { var Bar5 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar5, Foo); + var _super = _createSuper(Bar5); function Bar5() { _classCallCheck(this, Bar5); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar5).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar5; }(Foo); var Bar6 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar6, Foo); + var _super = _createSuper(Bar6); function Bar6() { _classCallCheck(this, Bar6); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar6).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar6; }(Foo); var Bar7 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar7, Foo); + var _super = _createSuper(Bar7); function Bar7() { _classCallCheck(this, Bar7); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar7).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar7; }(Foo); var Bar8 = /*#__PURE__*/ function(Foo) { "use strict"; _inherits(Bar8, Foo); + var _super = _createSuper(Bar8); function Bar8() { _classCallCheck(this, Bar8); - return _possibleConstructorReturn(this, _getPrototypeOf(Bar8).apply(this, arguments)); + return _super.apply(this, arguments); } return Bar8; }(Foo); diff --git a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.2.minified/output.js index fa9de7b037d..9fc12a25293 100644 --- a/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Foo1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Foo1 = function() { "use strict"; _classCallCheck(this, Foo1); }, Bar = function() { @@ -46,26 +62,34 @@ var _typeof = function(obj) { _classCallCheck(this, Bar4); }, Bar5 = function(Foo) { "use strict"; + _inherits(Bar5, Foo); + var _super = _createSuper(Bar5); function Bar5() { - return _classCallCheck(this, Bar5), _possibleConstructorReturn(this, _getPrototypeOf(Bar5).apply(this, arguments)); + return _classCallCheck(this, Bar5), _super.apply(this, arguments); } - return _inherits(Bar5, Foo), Bar5; + return Bar5; }(Foo1), Bar6 = function(Foo) { "use strict"; + _inherits(Bar6, Foo); + var _super = _createSuper(Bar6); function Bar6() { - return _classCallCheck(this, Bar6), _possibleConstructorReturn(this, _getPrototypeOf(Bar6).apply(this, arguments)); + return _classCallCheck(this, Bar6), _super.apply(this, arguments); } - return _inherits(Bar6, Foo), Bar6; + return Bar6; }(Foo1), Bar7 = function(Foo) { "use strict"; + _inherits(Bar7, Foo); + var _super = _createSuper(Bar7); function Bar7() { - return _classCallCheck(this, Bar7), _possibleConstructorReturn(this, _getPrototypeOf(Bar7).apply(this, arguments)); + return _classCallCheck(this, Bar7), _super.apply(this, arguments); } - return _inherits(Bar7, Foo), Bar7; + return Bar7; }(Foo1), Bar8 = function(Foo) { "use strict"; + _inherits(Bar8, Foo); + var _super = _createSuper(Bar8); function Bar8() { - return _classCallCheck(this, Bar8), _possibleConstructorReturn(this, _getPrototypeOf(Bar8).apply(this, arguments)); + return _classCallCheck(this, Bar8), _super.apply(this, arguments); } - return _inherits(Bar8, Foo), Bar8; + return Bar8; }(Foo1); diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.1.normal/output.js index 68074ee52b8..260028e292d 100644 --- a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A1; (function(A) { var Point = function Point() { @@ -58,9 +83,10 @@ var A1; var Point3d = /*#__PURE__*/ function(Point) { "use strict"; _inherits(Point3d, Point); + var _super = _createSuper(Point3d); function Point3d() { _classCallCheck(this, Point3d); - return _possibleConstructorReturn(this, _getPrototypeOf(Point3d).apply(this, arguments)); + return _super.apply(this, arguments); } return Point3d; }(Point); diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.2.minified/output.js index 1523352c1bb..9166b90817e 100644 --- a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations/input.ts/es5.2.minified/output.js @@ -23,14 +23,7 @@ function _setPrototypeOf(o, p) { }; var Point3d = function(Point) { "use strict"; - function Point3d() { - var self, call, obj; - return _classCallCheck(this, Point3d), self = this, call = _getPrototypeOf(Point3d).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +32,35 @@ function _setPrototypeOf(o, p) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Point3d, Point), Point3d; + }(Point3d, Point); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Point3d); + function Point3d() { + return _classCallCheck(this, Point3d), _super.apply(this, arguments); + } + return Point3d; }(Point1); A.Point3d = Point3d, A.Origin3d = { x: 0, diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.1.normal/output.js index 6988a5eb0cd..9d957828a83 100644 --- a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A1; (function(A) { var Point = function Point() { @@ -71,9 +96,10 @@ var A1; var Point3d = /*#__PURE__*/ function(Point) { "use strict"; _inherits(Point3d, Point); + var _super = _createSuper(Point3d); function Point3d() { _classCallCheck(this, Point3d); - return _possibleConstructorReturn(this, _getPrototypeOf(Point3d).apply(this, arguments)); + return _super.apply(this, arguments); } return Point3d; }(Point); diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.2.minified/output.js index 9a7640a9291..47af89ea7cc 100644 --- a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportClassWithInaccessibleTypeInTypeParameterConstraint/input.ts/es5.2.minified/output.js @@ -23,14 +23,7 @@ function _setPrototypeOf(o, p) { }; var Point3d = function(Point) { "use strict"; - function Point3d() { - var self, call, obj; - return _classCallCheck(this, Point3d), self = this, call = _getPrototypeOf(Point3d).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +32,35 @@ function _setPrototypeOf(o, p) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Point3d, Point), Point3d; + }(Point3d, Point); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Point3d); + function Point3d() { + return _classCallCheck(this, Point3d), _super.apply(this, arguments); + } + return Point3d; }(Point1); A.Point3d = Point3d, A.Origin3d = { x: 0, diff --git a/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.1.normal/output.js index aff1dca9975..c10cbeb547e 100644 --- a/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // expected no error var B1; (function(B) { @@ -51,9 +76,10 @@ var B1; var D = /*#__PURE__*/ function(_C) { "use strict"; _inherits(D, _C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(a.C); diff --git a/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.2.minified/output.js index f3902a44a32..16d3e275f0b 100644 --- a/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/importDeclarations/circularImportAlias/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ function _setPrototypeOf(o, p) { B.a = A1; var D = function(_C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return (function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ function _setPrototypeOf(o, p) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - })(D, _C), D; + }(D, _C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(a.C); B.D = D; }(B1 || (B1 = { diff --git a/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.1.normal/output.js index 282ef0fc636..9a41579ca1a 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} (function(A2) { var F = function F(s) { return 2; @@ -59,18 +84,20 @@ var _typeof = function(obj) { var B = /*#__PURE__*/ function(AA) { "use strict"; _inherits(B, AA); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(AA); var BB = /*#__PURE__*/ function(A) { "use strict"; _inherits(BB, A); + var _super = _createSuper(BB); function BB() { _classCallCheck(this, BB); - return _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _super.apply(this, arguments); } return BB; }(A1); @@ -118,9 +145,10 @@ var Y1; var B = /*#__PURE__*/ function(AA) { "use strict"; _inherits(B, AA); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(AA); @@ -128,9 +156,10 @@ var Y1; var BB = /*#__PURE__*/ function(A) { "use strict"; _inherits(BB, A); + var _super = _createSuper(BB); function BB() { _classCallCheck(this, BB); - return _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _super.apply(this, arguments); } return BB; }(A); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.2.minified/output.js index b8244ceb5de..b72da353965 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleBody/moduleWithStatementsOfEveryKind/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Y1; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,20 +17,35 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Y1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(A3) { var Module, Color, A1, Color1, A2 = function() { "use strict"; @@ -39,16 +55,20 @@ var Y1, _typeof = function(obj) { _classCallCheck(this, AA1); }, B = function(AA) { "use strict"; + _inherits(B, AA); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, AA), B; + return B; }(AA1), BB = function(A) { "use strict"; + _inherits(BB, A); + var _super = _createSuper(BB); function BB() { - return _classCallCheck(this, BB), _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _classCallCheck(this, BB), _super.apply(this, arguments); } - return _inherits(BB, A), BB; + return BB; }(A2); Module || (Module = { }), A1 = function() { @@ -70,18 +90,22 @@ var Y1, _typeof = function(obj) { Y.AA = AA2; var B = function(AA) { "use strict"; + _inherits(B, AA); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, AA), B; + return B; }(AA2); Y.B = B; var A4, Color2, BB = function(A) { "use strict"; + _inherits(BB, A); + var _super = _createSuper(BB); function BB() { - return _classCallCheck(this, BB), _possibleConstructorReturn(this, _getPrototypeOf(BB).apply(this, arguments)); + return _classCallCheck(this, BB), _super.apply(this, arguments); } - return _inherits(BB, A), BB; + return BB; }(A5); Y.BB = BB, Module || (Module = { }), A4 = function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.1.normal/output.js index d24d49817d5..8154c46b9f6 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.1.normal/output.js @@ -49,12 +49,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var ResizablePanel = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(ResizablePanel, _Component); + var _super = _createSuper(ResizablePanel); function ResizablePanel() { _classCallCheck(this, ResizablePanel); - return _possibleConstructorReturn(this, _getPrototypeOf(ResizablePanel).apply(this, arguments)); + return _super.apply(this, arguments); } return ResizablePanel; }(React.Component); diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.2.minified/output.js index c15fb94e575..01c8eddfe69 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenCanBeTupleTypex/input.tsx/es5.2.minified/output.js @@ -11,16 +11,7 @@ function _setPrototypeOf(o, p) { } var ResizablePanel = function(_Component) { "use strict"; - function ResizablePanel() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, ResizablePanel), self = this, call = _getPrototypeOf(ResizablePanel).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -29,6 +20,36 @@ var ResizablePanel = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(ResizablePanel, _Component), ResizablePanel; + }(ResizablePanel, _Component); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(ResizablePanel); + function ResizablePanel() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, ResizablePanel), _super.apply(this, arguments); + } + return ResizablePanel; }(React.Component); React.createElement(ResizablePanel, null, React.createElement("div", null), React.createElement("div", null)), React.createElement(ResizablePanel, null, React.createElement("div", null), React.createElement("div", null), React.createElement("div", null)); diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.1.normal/output.js index 0aba38ea912..94e2664104c 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { @@ -105,9 +131,10 @@ var Button = /*#__PURE__*/ function(_Component) { var InnerButton = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(InnerButton, _Component); + var _super = _createSuper(InnerButton); function InnerButton() { _classCallCheck(this, InnerButton); - return _possibleConstructorReturn(this, _getPrototypeOf(InnerButton).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(InnerButton, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.2.minified/output.js index 43d31451c4a..2f812177a85 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty12x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), Button = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), Button = function(_Component) { "use strict"; + _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { - return _classCallCheck(this, Button), _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _classCallCheck(this, Button), _super.apply(this, arguments); } - return _inherits(Button, _Component), _createClass(Button, [ + return _createClass(Button, [ { key: "render", value: function() { @@ -63,10 +81,12 @@ var _typeof = function(obj) { ]), Button; }(React.Component), InnerButton = function(_Component) { "use strict"; + _inherits(InnerButton, _Component); + var _super = _createSuper(InnerButton); function InnerButton() { - return _classCallCheck(this, InnerButton), _possibleConstructorReturn(this, _getPrototypeOf(InnerButton).apply(this, arguments)); + return _classCallCheck(this, InnerButton), _super.apply(this, arguments); } - return _inherits(InnerButton, _Component), _createClass(InnerButton, [ + return _createClass(InnerButton, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.1.normal/output.js index e448a38bf22..0abf4046c1a 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -82,9 +107,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { @@ -103,9 +129,10 @@ var Button = /*#__PURE__*/ function(_Component) { var InnerButton = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(InnerButton, _Component); + var _super = _createSuper(InnerButton); function InnerButton() { _classCallCheck(this, InnerButton); - return _possibleConstructorReturn(this, _getPrototypeOf(InnerButton).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(InnerButton, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.2.minified/output.js index 6c0385e07cb..1e42d6a82c4 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty13x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), Button = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), Button = function(_Component) { "use strict"; + _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { - return _classCallCheck(this, Button), _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _classCallCheck(this, Button), _super.apply(this, arguments); } - return _inherits(Button, _Component), _createClass(Button, [ + return _createClass(Button, [ { key: "render", value: function() { @@ -65,10 +83,12 @@ var _typeof = function(obj) { ]), Button; }(React.Component), InnerButton = function(_Component) { "use strict"; + _inherits(InnerButton, _Component); + var _super = _createSuper(InnerButton); function InnerButton() { - return _classCallCheck(this, InnerButton), _possibleConstructorReturn(this, _getPrototypeOf(InnerButton).apply(this, arguments)); + return _classCallCheck(this, InnerButton), _super.apply(this, arguments); } - return _inherits(InnerButton, _Component), _createClass(InnerButton, [ + return _createClass(InnerButton, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.1.normal/output.js index ca72c803c75..657248938ef 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.2.minified/output.js index 2a83d31942e..8bda211fd48 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty14x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Button = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Button() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Button), self = this, call = _getPrototypeOf(Button).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Button = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Button, _Component), Constructor = Button, protoProps = [ + }(Button, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Button); + function Button() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Button), _super.apply(this, arguments); + } + return Constructor = Button, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.1.normal/output.js index 5143b8b9016..b2ba675f038 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var FetchUser = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(FetchUser, _Component); + var _super = _createSuper(FetchUser); function FetchUser() { _classCallCheck(this, FetchUser); - return _possibleConstructorReturn(this, _getPrototypeOf(FetchUser).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(FetchUser, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.2.minified/output.js index 661b4da9f2e..0f64b87e4de 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty3x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var FetchUser = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function FetchUser() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, FetchUser), self = this, call = _getPrototypeOf(FetchUser).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var FetchUser = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(FetchUser, _Component), protoProps = [ + }(FetchUser, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(FetchUser); + function FetchUser() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, FetchUser), _super.apply(this, arguments); + } + return protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.1.normal/output.js index f2d71a7d7d8..d6d26605f62 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var FetchUser = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(FetchUser, _Component); + var _super = _createSuper(FetchUser); function FetchUser() { _classCallCheck(this, FetchUser); - return _possibleConstructorReturn(this, _getPrototypeOf(FetchUser).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(FetchUser, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.2.minified/output.js index 661b4da9f2e..0f64b87e4de 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty4x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var FetchUser = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function FetchUser() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, FetchUser), self = this, call = _getPrototypeOf(FetchUser).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var FetchUser = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(FetchUser, _Component), protoProps = [ + }(FetchUser, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(FetchUser); + function FetchUser() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, FetchUser), _super.apply(this, arguments); + } + return protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.1.normal/output.js index d2d8135de2a..8bea5234641 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.2.minified/output.js index 94eb5a7ebaf..9054e482614 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty5x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Button = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Button() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Button), self = this, call = _getPrototypeOf(Button).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Button = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Button, _Component), Constructor = Button, protoProps = [ + }(Button, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Button); + function Button() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Button), _super.apply(this, arguments); + } + return Constructor = Button, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.1.normal/output.js index 08da45f96d9..cf4829ee778 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.2.minified/output.js index b8085c40b73..7a6f7e8e337 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty6x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Button = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Button() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Button), self = this, call = _getPrototypeOf(Button).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Button = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Button, _Component), Constructor = Button, protoProps = [ + }(Button, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Button); + function Button() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Button), _super.apply(this, arguments); + } + return Constructor = Button, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.1.normal/output.js index 9b4149b0145..950711abef6 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.2.minified/output.js index 57ce2d4476c..8b4afed365f 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty7x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Button = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Button() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Button), self = this, call = _getPrototypeOf(Button).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Button = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Button, _Component), Constructor = Button, protoProps = [ + }(Button, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Button); + function Button() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Button), _super.apply(this, arguments); + } + return Constructor = Button, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.1.normal/output.js index 31f8c14b97b..1a23681b5df 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.2.minified/output.js index ba294bba495..8e8f8761002 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxChildrenProperty8x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Button = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Button() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Button), self = this, call = _getPrototypeOf(Button).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Button = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Button, _Component), Constructor = Button, protoProps = [ + }(Button, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Button); + function Button() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Button), _super.apply(this, arguments); + } + return Constructor = Button, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.1.normal/output.js index c7abd617e24..89f3b82a56c 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(Component) { "use strict"; _inherits(C, Component); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(Component); diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.2.minified/output.js index 97e61f2234d..1f36956b51a 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxIntersectionElementPropsTypex/input.tsx/es5.2.minified/output.js @@ -10,16 +10,7 @@ function _setPrototypeOf(o, p) { } var C = function(Component) { "use strict"; - function C() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -28,7 +19,37 @@ var C = function(Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Component), C; + }(C, Component); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, C), _super.apply(this, arguments); + } + return C; }(Component); new C({ foobar: "example" diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.1.normal/output.js index 89685622923..e58f1452d7c 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.1.normal/output.js @@ -94,12 +94,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var AsyncLoader = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(AsyncLoader, _Component); + var _super = _createSuper(AsyncLoader); function AsyncLoader() { _classCallCheck(this, AsyncLoader); - return _possibleConstructorReturn(this, _getPrototypeOf(AsyncLoader).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(AsyncLoader, [ { diff --git a/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.2.minified/output.js index 3d3aa1f7882..9d61ce83e33 100644 --- a/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/checkJsxSubtleSkipContextSensitiveBugx/input.tsx/es5.2.minified/output.js @@ -27,17 +27,7 @@ function _setPrototypeOf(o, p) { } var AsyncLoader = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function AsyncLoader() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, AsyncLoader), self = this, call = _getPrototypeOf(AsyncLoader).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,7 +36,37 @@ var AsyncLoader = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(AsyncLoader, _Component), protoProps = [ + }(AsyncLoader, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(AsyncLoader); + function AsyncLoader() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, AsyncLoader), _super.apply(this, arguments); + } + return protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.1.normal/output.js index 7a980cf03bc..ef2786931f1 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _this = this; // @filename: file.tsx // @jsx: preserve @@ -69,9 +94,10 @@ var React = require('react'); var BigGreeter = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(BigGreeter, _Component); + var _super = _createSuper(BigGreeter); function BigGreeter() { _classCallCheck(this, BigGreeter); - return _possibleConstructorReturn(this, _getPrototypeOf(BigGreeter).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(BigGreeter, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.2.minified/output.js index ad3a2a70ec3..1b1d65db467 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution15x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var _this = this, React = require("react"), BigGreeter = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function BigGreeter() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, BigGreeter), self = this, call = _getPrototypeOf(BigGreeter).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var _this = this, React = require("react"), BigGreeter = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(BigGreeter, _Component), Constructor = BigGreeter, protoProps = [ + }(BigGreeter, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(BigGreeter); + function BigGreeter() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, BigGreeter), _super.apply(this, arguments); + } + return Constructor = BigGreeter, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.1.normal/output.js index eda2ab1ada9..417c022fdb2 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); export var AddressComp = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(AddressComp, _Component); + var _super = _createSuper(AddressComp); function AddressComp() { _classCallCheck(this, AddressComp); - return _possibleConstructorReturn(this, _getPrototypeOf(AddressComp).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(AddressComp, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.2.minified/output.js index 7959994d983..e592df8107c 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxAttributeResolution16x/input.tsx/es5.2.minified/output.js @@ -17,17 +17,7 @@ function _setPrototypeOf(o, p) { var React = require("react"); export var AddressComp = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function AddressComp() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, AddressComp), self = this, call = _getPrototypeOf(AddressComp).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +26,37 @@ export var AddressComp = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(AddressComp, _Component), protoProps = [ + }(AddressComp, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(AddressComp); + function AddressComp() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, AddressComp), _super.apply(this, arguments); + } + return protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.1.normal/output.js index fd3848c7381..c8054be9e40 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.1.normal/output.js @@ -58,12 +58,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var ShortDetails = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(ShortDetails, _Component); + var _super = _createSuper(ShortDetails); function ShortDetails() { _classCallCheck(this, ShortDetails); - return _possibleConstructorReturn(this, _getPrototypeOf(ShortDetails).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(ShortDetails, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.2.minified/output.js index 58060b5150b..c311eb0df9b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxCorrectlyParseLessThanComparison1x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, ShortDetails = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function ShortDetails() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, ShortDetails), self = this, call = _getPrototypeOf(ShortDetails).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ export var _typeof, ShortDetails = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(ShortDetails, _Component), Constructor = ShortDetails, protoProps = [ + }(ShortDetails, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(ShortDetails); + function ShortDetails() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, ShortDetails), _super.apply(this, arguments); + } + return Constructor = ShortDetails, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.1.normal/output.js index 3010f05f2a0..99e8c43743d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.2.minified/output.js index baaa918169d..d2256df97a8 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution1x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.1.normal/output.js index 3010f05f2a0..99e8c43743d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.2.minified/output.js index baaa918169d..d2256df97a8 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution2x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.1.normal/output.js index 9ef9f86ac96..74ffdd39c95 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.2.minified/output.js index baaa918169d..d2256df97a8 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDefaultAttributesResolution3x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.1.normal/output.js index 239e7c5c285..062a38c7f4c 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.1.normal/output.js @@ -60,13 +60,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var Text = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Text, _Component); + var _super = _createSuper(Text); function Text() { _classCallCheck(this, Text); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._tagName = 'div'; return _this; } diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.2.minified/output.js index 9b544f44db5..3459400d98b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName5x/input.tsx/es5.2.minified/output.js @@ -17,17 +17,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, Text = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Text() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Text), self = this, call = _getPrototypeOf(Text).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._tagName = "div", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +26,38 @@ export var _typeof, Text = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Text, _Component), Constructor = Text, protoProps = [ + }(Text, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Text); + function Text() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Text), _this = _super.apply(this, arguments), _this._tagName = "div", _this; + } + return Constructor = Text, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.1.normal/output.js index 478613ea6e4..89119e3a9e9 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.1.normal/output.js @@ -60,13 +60,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var Text = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Text, _Component); + var _super = _createSuper(Text); function Text() { _classCallCheck(this, Text); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._tagName = 'div'; return _this; } diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.2.minified/output.js index 7656afa2147..1cae254430e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName7x/input.tsx/es5.2.minified/output.js @@ -17,17 +17,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, Text = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Text() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Text), self = this, call = _getPrototypeOf(Text).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._tagName = "div", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +26,38 @@ export var _typeof, Text = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Text, _Component), Constructor = Text, protoProps = [ + }(Text, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Text); + function Text() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Text), _this = _super.apply(this, arguments), _this._tagName = "div", _this; + } + return Constructor = Text, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.1.normal/output.js index 62c32c434bd..86da37ccd83 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.1.normal/output.js @@ -60,13 +60,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var Text = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Text, _Component); + var _super = _createSuper(Text); function Text() { _classCallCheck(this, Text); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._tagName = 'div'; return _this; } diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.2.minified/output.js index 324235cd123..5d4d964334e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName8x/input.tsx/es5.2.minified/output.js @@ -17,17 +17,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, Text = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Text() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Text), self = this, call = _getPrototypeOf(Text).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._tagName = "div", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +26,38 @@ export var _typeof, Text = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Text, _Component), Constructor = Text, protoProps = [ + }(Text, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Text); + function Text() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Text), _this = _super.apply(this, arguments), _this._tagName = "div", _this; + } + return Constructor = Text, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.1.normal/output.js index 62c32c434bd..86da37ccd83 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.1.normal/output.js @@ -60,13 +60,39 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var Text = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Text, _Component); + var _super = _createSuper(Text); function Text() { _classCallCheck(this, Text); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).apply(this, arguments)); + _this = _super.apply(this, arguments); _this._tagName = 'div'; return _this; } diff --git a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.2.minified/output.js index 324235cd123..5d4d964334e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxDynamicTagName9x/input.tsx/es5.2.minified/output.js @@ -17,17 +17,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, Text = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Text() { - var _this, self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Text), self = this, call = _getPrototypeOf(Text).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))._tagName = "div", _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -36,7 +26,38 @@ export var _typeof, Text = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Text, _Component), Constructor = Text, protoProps = [ + }(Text, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Text); + function Text() { + var _this; + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Text), _this = _super.apply(this, arguments), _this._tagName = "div", _this; + } + return Constructor = Text, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.1.normal/output.js index 4000fe2fef9..b6b6174c7f2 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.1.normal/output.js @@ -62,12 +62,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var App = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(App, _Component); + var _super = _createSuper(App); function App() { _classCallCheck(this, App); - return _possibleConstructorReturn(this, _getPrototypeOf(App).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(App, [ { @@ -82,9 +108,10 @@ export var App = /*#__PURE__*/ function(_Component) { export var Button = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { _classCallCheck(this, Button); - return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Button, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.2.minified/output.js index e289662af2f..f8681304d5f 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxExternalModuleEmit1x/input.tsx/es5.2.minified/output.js @@ -27,26 +27,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; -export var App = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +export var _typeof, App = function(_Component) { "use strict"; + _inherits(App, _Component); + var _super = _createSuper(App); function App() { - return _classCallCheck(this, App), _possibleConstructorReturn(this, _getPrototypeOf(App).apply(this, arguments)); + return _classCallCheck(this, App), _super.apply(this, arguments); } - return _inherits(App, _Component), _createClass(App, [ + return _createClass(App, [ { key: "render", value: function() { @@ -57,10 +74,12 @@ export var App = function(_Component) { }(React.Component); export var Button = function(_Component) { "use strict"; + _inherits(Button, _Component); + var _super = _createSuper(Button); function Button() { - return _classCallCheck(this, Button), _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments)); + return _classCallCheck(this, Button), _super.apply(this, arguments); } - return _inherits(Button, _Component), _createClass(Button, [ + return _createClass(Button, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.1.normal/output.js index 4c536d8968a..acad9baea7b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var B1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { _classCallCheck(this, B1); - return _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B1, [ { @@ -98,9 +124,10 @@ var B1 = /*#__PURE__*/ function(_Component) { var B = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B, _Component); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.2.minified/output.js index d708382826d..325c5ed796e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType3x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), B1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), B1 = function(_Component) { "use strict"; + _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { - return _classCallCheck(this, B1), _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _classCallCheck(this, B1), _super.apply(this, arguments); } - return _inherits(B1, _Component), _createClass(B1, [ + return _createClass(B1, [ { key: "render", value: function() { @@ -62,10 +80,12 @@ var _typeof = function(obj) { ]), B1; }(React.Component), B = function(_Component) { "use strict"; + _inherits(B, _Component); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, _Component), _createClass(B, [ + return _createClass(B, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.1.normal/output.js index 4c536d8968a..acad9baea7b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var B1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { _classCallCheck(this, B1); - return _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B1, [ { @@ -98,9 +124,10 @@ var B1 = /*#__PURE__*/ function(_Component) { var B = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B, _Component); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.2.minified/output.js index d708382826d..325c5ed796e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType4x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), B1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), B1 = function(_Component) { "use strict"; + _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { - return _classCallCheck(this, B1), _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _classCallCheck(this, B1), _super.apply(this, arguments); } - return _inherits(B1, _Component), _createClass(B1, [ + return _createClass(B1, [ { key: "render", value: function() { @@ -62,10 +80,12 @@ var _typeof = function(obj) { ]), B1; }(React.Component), B = function(_Component) { "use strict"; + _inherits(B, _Component); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, _Component), _createClass(B, [ + return _createClass(B, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.1.normal/output.js index 4c536d8968a..acad9baea7b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var B1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { _classCallCheck(this, B1); - return _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B1, [ { @@ -98,9 +124,10 @@ var B1 = /*#__PURE__*/ function(_Component) { var B = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B, _Component); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.2.minified/output.js index d708382826d..325c5ed796e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType5x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), B1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), B1 = function(_Component) { "use strict"; + _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { - return _classCallCheck(this, B1), _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _classCallCheck(this, B1), _super.apply(this, arguments); } - return _inherits(B1, _Component), _createClass(B1, [ + return _createClass(B1, [ { key: "render", value: function() { @@ -62,10 +80,12 @@ var _typeof = function(obj) { ]), B1; }(React.Component), B = function(_Component) { "use strict"; + _inherits(B, _Component); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, _Component), _createClass(B, [ + return _createClass(B, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.1.normal/output.js index 4c536d8968a..acad9baea7b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var B1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { _classCallCheck(this, B1); - return _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B1, [ { @@ -98,9 +124,10 @@ var B1 = /*#__PURE__*/ function(_Component) { var B = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(B, _Component); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.2.minified/output.js index d708382826d..325c5ed796e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType6x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), B1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), B1 = function(_Component) { "use strict"; + _inherits(B1, _Component); + var _super = _createSuper(B1); function B1() { - return _classCallCheck(this, B1), _possibleConstructorReturn(this, _getPrototypeOf(B1).apply(this, arguments)); + return _classCallCheck(this, B1), _super.apply(this, arguments); } - return _inherits(B1, _Component), _createClass(B1, [ + return _createClass(B1, [ { key: "render", value: function() { @@ -62,10 +80,12 @@ var _typeof = function(obj) { ]), B1; }(React.Component), B = function(_Component) { "use strict"; + _inherits(B, _Component); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, _Component), _createClass(B, [ + return _createClass(B, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.1.normal/output.js index c54caa50e10..d6653370cd5 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -82,9 +107,10 @@ export function makeP(Ctor) { return /*#__PURE__*/ (function(_PureComponent) { "use strict"; _inherits(_class, _PureComponent); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(_class, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.2.minified/output.js index 0b06632d1ff..e162b6e1e81 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxGenericAttributesType9x/input.tsx/es5.2.minified/output.js @@ -27,17 +27,7 @@ var React1 = require("react"); export function makeP(Ctor) { return (function(_PureComponent) { "use strict"; - var Constructor, protoProps, staticProps; - function _class() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, _class), self = this, call = _getPrototypeOf(_class).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,7 +36,37 @@ export function makeP(Ctor) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(_class, _PureComponent), Constructor = _class, protoProps = [ + }(_class, _PureComponent); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(_class); + function _class() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, _class), _super.apply(this, arguments); + } + return Constructor = _class, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.1.normal/output.js index 4bf3bcf2f53..55ee96f0414 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Component = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(Component, ReactComponent); + var _super = _createSuper(Component); function Component() { _classCallCheck(this, Component); - return _possibleConstructorReturn(this, _getPrototypeOf(Component).apply(this, arguments)); + return _super.apply(this, arguments); } return Component; }(ReactComponent); @@ -91,9 +117,10 @@ var f = /*#__PURE__*/ React.createElement(Component, { var JustPropTypes = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(JustPropTypes, ReactComponent); + var _super = _createSuper(JustPropTypes); function JustPropTypes() { _classCallCheck(this, JustPropTypes); - return _possibleConstructorReturn(this, _getPrototypeOf(JustPropTypes).apply(this, arguments)); + return _super.apply(this, arguments); } return JustPropTypes; }(ReactComponent); @@ -119,9 +146,10 @@ var j = /*#__PURE__*/ React.createElement(JustPropTypes, { var JustDefaultProps = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(JustDefaultProps, ReactComponent); + var _super = _createSuper(JustDefaultProps); function JustDefaultProps() { _classCallCheck(this, JustDefaultProps); - return _possibleConstructorReturn(this, _getPrototypeOf(JustDefaultProps).apply(this, arguments)); + return _super.apply(this, arguments); } return JustDefaultProps; }(ReactComponent); @@ -141,9 +169,10 @@ var m = /*#__PURE__*/ React.createElement(JustDefaultProps, { var BothWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(BothWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(BothWithSpecifiedGeneric); function BothWithSpecifiedGeneric() { _classCallCheck(this, BothWithSpecifiedGeneric); - return _possibleConstructorReturn(this, _getPrototypeOf(BothWithSpecifiedGeneric).apply(this, arguments)); + return _super.apply(this, arguments); } return BothWithSpecifiedGeneric; }(ReactComponent); @@ -185,9 +214,10 @@ var s = /*#__PURE__*/ React.createElement(BothWithSpecifiedGeneric, { var JustPropTypesWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(JustPropTypesWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(JustPropTypesWithSpecifiedGeneric); function JustPropTypesWithSpecifiedGeneric() { _classCallCheck(this, JustPropTypesWithSpecifiedGeneric); - return _possibleConstructorReturn(this, _getPrototypeOf(JustPropTypesWithSpecifiedGeneric).apply(this, arguments)); + return _super.apply(this, arguments); } return JustPropTypesWithSpecifiedGeneric; }(ReactComponent); @@ -213,9 +243,10 @@ var w = /*#__PURE__*/ React.createElement(JustPropTypesWithSpecifiedGeneric, { var JustDefaultPropsWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent) { "use strict"; _inherits(JustDefaultPropsWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(JustDefaultPropsWithSpecifiedGeneric); function JustDefaultPropsWithSpecifiedGeneric() { _classCallCheck(this, JustDefaultPropsWithSpecifiedGeneric); - return _possibleConstructorReturn(this, _getPrototypeOf(JustDefaultPropsWithSpecifiedGeneric).apply(this, arguments)); + return _super.apply(this, arguments); } return JustDefaultPropsWithSpecifiedGeneric; }(ReactComponent); diff --git a/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.2.minified/output.js index c6ba635dc6a..5c09f94324d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxLibraryManagedAttributesx/input.tsx/es5.2.minified/output.js @@ -16,25 +16,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Component = function(ReactComponent) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Component = function(ReactComponent) { "use strict"; + _inherits(Component, ReactComponent); + var _super = _createSuper(Component); function Component() { - return _classCallCheck(this, Component), _possibleConstructorReturn(this, _getPrototypeOf(Component).apply(this, arguments)); + return _classCallCheck(this, Component), _super.apply(this, arguments); } - return _inherits(Component, ReactComponent), Component; + return Component; }(ReactComponent); Component.propTypes = { foo: PropTypes.number, @@ -66,10 +84,12 @@ Component.propTypes = { }); var JustPropTypes = function(ReactComponent) { "use strict"; + _inherits(JustPropTypes, ReactComponent); + var _super = _createSuper(JustPropTypes); function JustPropTypes() { - return _classCallCheck(this, JustPropTypes), _possibleConstructorReturn(this, _getPrototypeOf(JustPropTypes).apply(this, arguments)); + return _classCallCheck(this, JustPropTypes), _super.apply(this, arguments); } - return _inherits(JustPropTypes, ReactComponent), JustPropTypes; + return JustPropTypes; }(ReactComponent); JustPropTypes.propTypes = { foo: PropTypes.number, @@ -88,10 +108,12 @@ JustPropTypes.propTypes = { }); var JustDefaultProps = function(ReactComponent) { "use strict"; + _inherits(JustDefaultProps, ReactComponent); + var _super = _createSuper(JustDefaultProps); function JustDefaultProps() { - return _classCallCheck(this, JustDefaultProps), _possibleConstructorReturn(this, _getPrototypeOf(JustDefaultProps).apply(this, arguments)); + return _classCallCheck(this, JustDefaultProps), _super.apply(this, arguments); } - return _inherits(JustDefaultProps, ReactComponent), JustDefaultProps; + return JustDefaultProps; }(ReactComponent); JustDefaultProps.defaultProps = { foo: 42 @@ -105,10 +127,12 @@ JustDefaultProps.defaultProps = { }); var BothWithSpecifiedGeneric = function(ReactComponent) { "use strict"; + _inherits(BothWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(BothWithSpecifiedGeneric); function BothWithSpecifiedGeneric() { - return _classCallCheck(this, BothWithSpecifiedGeneric), _possibleConstructorReturn(this, _getPrototypeOf(BothWithSpecifiedGeneric).apply(this, arguments)); + return _classCallCheck(this, BothWithSpecifiedGeneric), _super.apply(this, arguments); } - return _inherits(BothWithSpecifiedGeneric, ReactComponent), BothWithSpecifiedGeneric; + return BothWithSpecifiedGeneric; }(ReactComponent); BothWithSpecifiedGeneric.propTypes = { foo: PropTypes.string, @@ -140,10 +164,12 @@ BothWithSpecifiedGeneric.propTypes = { }); var JustPropTypesWithSpecifiedGeneric = function(ReactComponent) { "use strict"; + _inherits(JustPropTypesWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(JustPropTypesWithSpecifiedGeneric); function JustPropTypesWithSpecifiedGeneric() { - return _classCallCheck(this, JustPropTypesWithSpecifiedGeneric), _possibleConstructorReturn(this, _getPrototypeOf(JustPropTypesWithSpecifiedGeneric).apply(this, arguments)); + return _classCallCheck(this, JustPropTypesWithSpecifiedGeneric), _super.apply(this, arguments); } - return _inherits(JustPropTypesWithSpecifiedGeneric, ReactComponent), JustPropTypesWithSpecifiedGeneric; + return JustPropTypesWithSpecifiedGeneric; }(ReactComponent); JustPropTypesWithSpecifiedGeneric.propTypes = { foo: PropTypes.string, @@ -162,10 +188,12 @@ JustPropTypesWithSpecifiedGeneric.propTypes = { }); var JustDefaultPropsWithSpecifiedGeneric = function(ReactComponent) { "use strict"; + _inherits(JustDefaultPropsWithSpecifiedGeneric, ReactComponent); + var _super = _createSuper(JustDefaultPropsWithSpecifiedGeneric); function JustDefaultPropsWithSpecifiedGeneric() { - return _classCallCheck(this, JustDefaultPropsWithSpecifiedGeneric), _possibleConstructorReturn(this, _getPrototypeOf(JustDefaultPropsWithSpecifiedGeneric).apply(this, arguments)); + return _classCallCheck(this, JustDefaultPropsWithSpecifiedGeneric), _super.apply(this, arguments); } - return _inherits(JustDefaultPropsWithSpecifiedGeneric, ReactComponent), JustDefaultPropsWithSpecifiedGeneric; + return JustDefaultPropsWithSpecifiedGeneric; }(ReactComponent); JustDefaultPropsWithSpecifiedGeneric.defaultProps = { foo: "no" diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.1.normal/output.js index a2e93d45b0e..250487109b8 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Opt = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Opt, _Component); + var _super = _createSuper(Opt); function Opt() { _classCallCheck(this, Opt); - return _possibleConstructorReturn(this, _getPrototypeOf(Opt).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Opt, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.2.minified/output.js index 32bb1f60c54..232babcb19c 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution10x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Opt = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Opt() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Opt), self = this, call = _getPrototypeOf(Opt).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), Opt = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Opt, _Component), Constructor = Opt, protoProps = [ + }(Opt, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Opt); + function Opt() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Opt), _super.apply(this, arguments); + } + return Constructor = Opt, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.1.normal/output.js index de5394a242c..38c0e2136ba 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -90,9 +115,10 @@ var obj3 = { var OverWriteAttr = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(OverWriteAttr, _Component); + var _super = _createSuper(OverWriteAttr); function OverWriteAttr() { _classCallCheck(this, OverWriteAttr); - return _possibleConstructorReturn(this, _getPrototypeOf(OverWriteAttr).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(OverWriteAttr, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.2.minified/output.js index 2fd339d6b57..df088c5fc15 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution11x/input.tsx/es5.2.minified/output.js @@ -27,17 +27,7 @@ var anyobj, React = require("react"), obj1 = { x: 2 }, OverWriteAttr = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function OverWriteAttr() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, OverWriteAttr), self = this, call = _getPrototypeOf(OverWriteAttr).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,7 +36,37 @@ var anyobj, React = require("react"), obj1 = { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(OverWriteAttr, _Component), Constructor = OverWriteAttr, protoProps = [ + }(OverWriteAttr, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(OverWriteAttr); + function OverWriteAttr() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, OverWriteAttr), _super.apply(this, arguments); + } + return Constructor = OverWriteAttr, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.1.normal/output.js index 7fc05148de8..14290a34cd3 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -90,9 +115,10 @@ var obj3 = { var OverWriteAttr = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(OverWriteAttr, _Component); + var _super = _createSuper(OverWriteAttr); function OverWriteAttr() { _classCallCheck(this, OverWriteAttr); - return _possibleConstructorReturn(this, _getPrototypeOf(OverWriteAttr).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(OverWriteAttr, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.2.minified/output.js index 749f5f144ae..267383c7da3 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution12x/input.tsx/es5.2.minified/output.js @@ -27,17 +27,7 @@ var anyobj, React = require("react"), obj1 = { x: 2 }, OverWriteAttr = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function OverWriteAttr() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, OverWriteAttr), self = this, call = _getPrototypeOf(OverWriteAttr).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,7 +36,37 @@ var anyobj, React = require("react"), obj1 = { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(OverWriteAttr, _Component), Constructor = OverWriteAttr, protoProps = [ + }(OverWriteAttr, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(OverWriteAttr); + function OverWriteAttr() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, OverWriteAttr), _super.apply(this, arguments); + } + return Constructor = OverWriteAttr, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.1.normal/output.js index 19b4d2d6e5b..0555240dd87 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.1.normal/output.js @@ -72,12 +72,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} export var Empty = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Empty, _Component); + var _super = _createSuper(Empty); function Empty() { _classCallCheck(this, Empty); - return _possibleConstructorReturn(this, _getPrototypeOf(Empty).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Empty, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.2.minified/output.js index 6f41fbdb221..74048459cce 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution17x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } export var _typeof, Empty = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Empty() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Empty), self = this, call = _getPrototypeOf(Empty).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ export var _typeof, Empty = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Empty, _Component), Constructor = Empty, protoProps = [ + }(Empty, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Empty); + function Empty() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Empty), _super.apply(this, arguments); + } + return Constructor = Empty, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.1.normal/output.js index 70b0d92d6cb..d27a6432a9e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.2.minified/output.js index c1ce48fa9fc..ab9f4668ef5 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution1x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.1.normal/output.js index 9c20046b3f8..d53d48e36f2 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.2.minified/output.js index 9ec33e95148..a1e2b79cc0b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution2x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.1.normal/output.js index 8255673a986..c472c13a06d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.2.minified/output.js index 74891ca4eb6..099b451e95b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution3x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Poisoned = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Poisoned() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Poisoned), self = this, call = _getPrototypeOf(Poisoned).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), Poisoned = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Poisoned, _Component), Constructor = Poisoned, protoProps = [ + }(Poisoned, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Poisoned); + function Poisoned() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Poisoned), _super.apply(this, arguments); + } + return Constructor = Poisoned, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.1.normal/output.js index 8870c899cdb..d966fc05519 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _this = this; // @filename: file.tsx // @jsx: preserve @@ -82,9 +107,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { @@ -106,9 +132,10 @@ var p1 = /*#__PURE__*/ React.createElement(Poisoned, _extends({ var EmptyProp = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(EmptyProp, _Component); + var _super = _createSuper(EmptyProp); function EmptyProp() { _classCallCheck(this, EmptyProp); - return _possibleConstructorReturn(this, _getPrototypeOf(EmptyProp).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(EmptyProp, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.2.minified/output.js index 79820970d4f..66a240e0ebd 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution4x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var j, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _this = this, React = require("react"), Poisoned = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var j, _this = this, React = require("react"), Poisoned = function(_Component) { "use strict"; + _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { - return _classCallCheck(this, Poisoned), _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _classCallCheck(this, Poisoned), _super.apply(this, arguments); } - return _inherits(Poisoned, _Component), _createClass(Poisoned, [ + return _createClass(Poisoned, [ { key: "render", value: function() { @@ -68,10 +86,12 @@ React.createElement(Poisoned, _extends({ })); var EmptyProp = function(_Component) { "use strict"; + _inherits(EmptyProp, _Component); + var _super = _createSuper(EmptyProp); function EmptyProp() { - return _classCallCheck(this, EmptyProp), _possibleConstructorReturn(this, _getPrototypeOf(EmptyProp).apply(this, arguments)); + return _classCallCheck(this, EmptyProp), _super.apply(this, arguments); } - return _inherits(EmptyProp, _Component), _createClass(EmptyProp, [ + return _createClass(EmptyProp, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.1.normal/output.js index ab4b18a5479..ae7dd403cf9 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Poisoned = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { _classCallCheck(this, Poisoned); - return _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Poisoned, [ { @@ -105,9 +131,10 @@ var p1 = /*#__PURE__*/ React.createElement(Poisoned, _extends({ var EmptyProp = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(EmptyProp, _Component); + var _super = _createSuper(EmptyProp); function EmptyProp() { _classCallCheck(this, EmptyProp); - return _possibleConstructorReturn(this, _getPrototypeOf(EmptyProp).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(EmptyProp, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.2.minified/output.js index e0158c77f9c..86a9d7cb3c8 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution5x/input.tsx/es5.2.minified/output.js @@ -34,25 +34,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), Poisoned = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), Poisoned = function(_Component) { "use strict"; + _inherits(Poisoned, _Component); + var _super = _createSuper(Poisoned); function Poisoned() { - return _classCallCheck(this, Poisoned), _possibleConstructorReturn(this, _getPrototypeOf(Poisoned).apply(this, arguments)); + return _classCallCheck(this, Poisoned), _super.apply(this, arguments); } - return _inherits(Poisoned, _Component), _createClass(Poisoned, [ + return _createClass(Poisoned, [ { key: "render", value: function() { @@ -68,10 +86,12 @@ React.createElement(Poisoned, _extends({ })); var EmptyProp = function(_Component) { "use strict"; + _inherits(EmptyProp, _Component); + var _super = _createSuper(EmptyProp); function EmptyProp() { - return _classCallCheck(this, EmptyProp), _possibleConstructorReturn(this, _getPrototypeOf(EmptyProp).apply(this, arguments)); + return _classCallCheck(this, EmptyProp), _super.apply(this, arguments); } - return _inherits(EmptyProp, _Component), _createClass(EmptyProp, [ + return _createClass(EmptyProp, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.1.normal/output.js index 4f036089834..d99958cd379 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var TextComponent = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(TextComponent, _Component); + var _super = _createSuper(TextComponent); function TextComponent() { _classCallCheck(this, TextComponent); - return _possibleConstructorReturn(this, _getPrototypeOf(TextComponent).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(TextComponent, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.2.minified/output.js index 225b5e4df1b..83b936bdccc 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution6x/input.tsx/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), TextComponent = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function TextComponent() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, TextComponent), self = this, call = _getPrototypeOf(TextComponent).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var React = require("react"), TextComponent = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(TextComponent, _Component), Constructor = TextComponent, protoProps = [ + }(TextComponent, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(TextComponent); + function TextComponent() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, TextComponent), _super.apply(this, arguments); + } + return Constructor = TextComponent, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.1.normal/output.js index b5491260096..a4971a03958 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var TextComponent = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(TextComponent, _Component); + var _super = _createSuper(TextComponent); function TextComponent() { _classCallCheck(this, TextComponent); - return _possibleConstructorReturn(this, _getPrototypeOf(TextComponent).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(TextComponent, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.2.minified/output.js index 8490cce5fa0..f7060a43c92 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution7x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), TextComponent = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function TextComponent() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, TextComponent), self = this, call = _getPrototypeOf(TextComponent).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), TextComponent = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(TextComponent, _Component), Constructor = TextComponent, protoProps = [ + }(TextComponent, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(TextComponent); + function TextComponent() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, TextComponent), _super.apply(this, arguments); + } + return Constructor = TextComponent, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.1.normal/output.js index d2ecb1ed539..e622a8f4bbb 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -90,9 +115,10 @@ var obj3 = { var OverWriteAttr = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(OverWriteAttr, _Component); + var _super = _createSuper(OverWriteAttr); function OverWriteAttr() { _classCallCheck(this, OverWriteAttr); - return _possibleConstructorReturn(this, _getPrototypeOf(OverWriteAttr).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(OverWriteAttr, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.2.minified/output.js index 091b36e453f..dc943c75d6b 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution8x/input.tsx/es5.2.minified/output.js @@ -27,17 +27,7 @@ var React = require("react"), obj1 = { x: 2 }, OverWriteAttr = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function OverWriteAttr() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, OverWriteAttr), self = this, call = _getPrototypeOf(OverWriteAttr).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -46,7 +36,37 @@ var React = require("react"), obj1 = { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(OverWriteAttr, _Component), Constructor = OverWriteAttr, protoProps = [ + }(OverWriteAttr, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(OverWriteAttr); + function OverWriteAttr() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, OverWriteAttr), _super.apply(this, arguments); + } + return Constructor = OverWriteAttr, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.1.normal/output.js index 379f66cd568..6ee15911a20 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.1.normal/output.js @@ -72,6 +72,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -81,9 +106,10 @@ var React = require('react'); var Opt = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(Opt, _Component); + var _super = _createSuper(Opt); function Opt() { _classCallCheck(this, Opt); - return _possibleConstructorReturn(this, _getPrototypeOf(Opt).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Opt, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.2.minified/output.js index 713ce7b3ba6..99d0d8c0d2d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxSpreadAttributesResolution9x/input.tsx/es5.2.minified/output.js @@ -25,17 +25,7 @@ function _setPrototypeOf(o, p) { } var React = require("react"), Opt = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function Opt() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Opt), self = this, call = _getPrototypeOf(Opt).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -44,7 +34,37 @@ var React = require("react"), Opt = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Opt, _Component), Constructor = Opt, protoProps = [ + }(Opt, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Opt); + function Opt() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Opt), _super.apply(this, arguments); + } + return Constructor = Opt, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.1.normal/output.js index df6756202c3..36ac9ff3420 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: preserve // @noLib: true @@ -70,9 +95,10 @@ function Greet(x) { var BigGreeter = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(BigGreeter, _Component); + var _super = _createSuper(BigGreeter); function BigGreeter() { _classCallCheck(this, BigGreeter); - return _possibleConstructorReturn(this, _getPrototypeOf(BigGreeter).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(BigGreeter, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.2.minified/output.js index abe494d3b48..ac44a10df79 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxStatelessFunctionComponents2x/input.tsx/es5.2.minified/output.js @@ -20,17 +20,7 @@ function Greet(x) { } var BigGreeter = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; - function BigGreeter() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, BigGreeter), self = this, call = _getPrototypeOf(BigGreeter).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +29,37 @@ var BigGreeter = function(_Component) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(BigGreeter, _Component), Constructor = BigGreeter, protoProps = [ + }(BigGreeter, _Component); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(BigGreeter); + function BigGreeter() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, BigGreeter), _super.apply(this, arguments); + } + return Constructor = BigGreeter, protoProps = [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.1.normal/output.js index 37f4fcd4c05..6ddc6c84b7d 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: react // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var RC1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC1, _Component); + var _super = _createSuper(RC1); function RC1() { _classCallCheck(this, RC1); - return _possibleConstructorReturn(this, _getPrototypeOf(RC1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC1, [ { @@ -84,9 +110,10 @@ var RC1 = /*#__PURE__*/ function(_Component) { var RC2 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC2, _Component); + var _super = _createSuper(RC2); function RC2() { _classCallCheck(this, RC2); - return _possibleConstructorReturn(this, _getPrototypeOf(RC2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC2, [ { @@ -106,9 +133,10 @@ var RC2 = /*#__PURE__*/ function(_Component) { var RC3 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC3, _Component); + var _super = _createSuper(RC3); function RC3() { _classCallCheck(this, RC3); - return _possibleConstructorReturn(this, _getPrototypeOf(RC3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC3, [ { @@ -123,9 +151,10 @@ var RC3 = /*#__PURE__*/ function(_Component) { var RC4 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC4, _Component); + var _super = _createSuper(RC4); function RC4() { _classCallCheck(this, RC4); - return _possibleConstructorReturn(this, _getPrototypeOf(RC4).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC4, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.2.minified/output.js index 4cb6042b768..0e473be6981 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType3x/input.tsx/es5.2.minified/output.js @@ -25,25 +25,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), RC1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), RC1 = function(_Component) { "use strict"; + _inherits(RC1, _Component); + var _super = _createSuper(RC1); function RC1() { - return _classCallCheck(this, RC1), _possibleConstructorReturn(this, _getPrototypeOf(RC1).apply(this, arguments)); + return _classCallCheck(this, RC1), _super.apply(this, arguments); } - return _inherits(RC1, _Component), _createClass(RC1, [ + return _createClass(RC1, [ { key: "render", value: function() { @@ -53,10 +71,12 @@ var _typeof = function(obj) { ]), RC1; }(React.Component), RC2 = function(_Component) { "use strict"; + _inherits(RC2, _Component); + var _super = _createSuper(RC2); function RC2() { - return _classCallCheck(this, RC2), _possibleConstructorReturn(this, _getPrototypeOf(RC2).apply(this, arguments)); + return _classCallCheck(this, RC2), _super.apply(this, arguments); } - return _inherits(RC2, _Component), _createClass(RC2, [ + return _createClass(RC2, [ { key: "render", value: function() { @@ -71,10 +91,12 @@ var _typeof = function(obj) { ]), RC2; }(React.Component), RC3 = function(_Component) { "use strict"; + _inherits(RC3, _Component); + var _super = _createSuper(RC3); function RC3() { - return _classCallCheck(this, RC3), _possibleConstructorReturn(this, _getPrototypeOf(RC3).apply(this, arguments)); + return _classCallCheck(this, RC3), _super.apply(this, arguments); } - return _inherits(RC3, _Component), _createClass(RC3, [ + return _createClass(RC3, [ { key: "render", value: function() { @@ -84,10 +106,12 @@ var _typeof = function(obj) { ]), RC3; }(React.Component), RC4 = function(_Component) { "use strict"; + _inherits(RC4, _Component); + var _super = _createSuper(RC4); function RC4() { - return _classCallCheck(this, RC4), _possibleConstructorReturn(this, _getPrototypeOf(RC4).apply(this, arguments)); + return _classCallCheck(this, RC4), _super.apply(this, arguments); } - return _inherits(RC4, _Component), _createClass(RC4, [ + return _createClass(RC4, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.1.normal/output.js index 937117d8561..470f5925a6c 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: react // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var RC1 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC1, _Component); + var _super = _createSuper(RC1); function RC1() { _classCallCheck(this, RC1); - return _possibleConstructorReturn(this, _getPrototypeOf(RC1).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC1, [ { @@ -84,9 +110,10 @@ var RC1 = /*#__PURE__*/ function(_Component) { var RC2 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC2, _Component); + var _super = _createSuper(RC2); function RC2() { _classCallCheck(this, RC2); - return _possibleConstructorReturn(this, _getPrototypeOf(RC2).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC2, [ { @@ -106,9 +133,10 @@ var RC2 = /*#__PURE__*/ function(_Component) { var RC3 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC3, _Component); + var _super = _createSuper(RC3); function RC3() { _classCallCheck(this, RC3); - return _possibleConstructorReturn(this, _getPrototypeOf(RC3).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC3, [ { @@ -123,9 +151,10 @@ var RC3 = /*#__PURE__*/ function(_Component) { var RC4 = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(RC4, _Component); + var _super = _createSuper(RC4); function RC4() { _classCallCheck(this, RC4); - return _possibleConstructorReturn(this, _getPrototypeOf(RC4).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(RC4, [ { diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.2.minified/output.js index 7c9e78807ed..e84ca1f9ab9 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionElementType4x/input.tsx/es5.2.minified/output.js @@ -25,25 +25,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), RC1 = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), RC1 = function(_Component) { "use strict"; + _inherits(RC1, _Component); + var _super = _createSuper(RC1); function RC1() { - return _classCallCheck(this, RC1), _possibleConstructorReturn(this, _getPrototypeOf(RC1).apply(this, arguments)); + return _classCallCheck(this, RC1), _super.apply(this, arguments); } - return _inherits(RC1, _Component), _createClass(RC1, [ + return _createClass(RC1, [ { key: "render", value: function() { @@ -53,10 +71,12 @@ var _typeof = function(obj) { ]), RC1; }(React.Component), RC2 = function(_Component) { "use strict"; + _inherits(RC2, _Component); + var _super = _createSuper(RC2); function RC2() { - return _classCallCheck(this, RC2), _possibleConstructorReturn(this, _getPrototypeOf(RC2).apply(this, arguments)); + return _classCallCheck(this, RC2), _super.apply(this, arguments); } - return _inherits(RC2, _Component), _createClass(RC2, [ + return _createClass(RC2, [ { key: "render", value: function() { @@ -71,10 +91,12 @@ var _typeof = function(obj) { ]), RC2; }(React.Component), RC3 = function(_Component) { "use strict"; + _inherits(RC3, _Component); + var _super = _createSuper(RC3); function RC3() { - return _classCallCheck(this, RC3), _possibleConstructorReturn(this, _getPrototypeOf(RC3).apply(this, arguments)); + return _classCallCheck(this, RC3), _super.apply(this, arguments); } - return _inherits(RC3, _Component), _createClass(RC3, [ + return _createClass(RC3, [ { key: "render", value: function() { @@ -84,10 +106,12 @@ var _typeof = function(obj) { ]), RC3; }(React.Component), RC4 = function(_Component) { "use strict"; + _inherits(RC4, _Component); + var _super = _createSuper(RC4); function RC4() { - return _classCallCheck(this, RC4), _possibleConstructorReturn(this, _getPrototypeOf(RC4).apply(this, arguments)); + return _classCallCheck(this, RC4), _super.apply(this, arguments); } - return _inherits(RC4, _Component), _createClass(RC4, [ + return _createClass(RC4, [ { key: "render", value: function() { diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.1.normal/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.1.normal/output.js index 80aafff44cc..36bc44b0476 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @filename: file.tsx // @jsx: react // @noLib: true @@ -67,9 +92,10 @@ var React = require('react'); var MyComponent = /*#__PURE__*/ function(_Component) { "use strict"; _inherits(MyComponent, _Component); + var _super = _createSuper(MyComponent); function MyComponent() { _classCallCheck(this, MyComponent); - return _possibleConstructorReturn(this, _getPrototypeOf(MyComponent).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(MyComponent, [ { @@ -92,9 +118,10 @@ var MyButtonComponent = // Component Class as Props /*#__PURE__*/ function(_Component) { "use strict"; _inherits(MyButtonComponent, _Component); + var _super = _createSuper(MyButtonComponent); function MyButtonComponent() { _classCallCheck(this, MyButtonComponent); - return _possibleConstructorReturn(this, _getPrototypeOf(MyButtonComponent).apply(this, arguments)); + return _super.apply(this, arguments); } return MyButtonComponent; }(React.Component); diff --git a/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.2.minified/output.js b/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.2.minified/output.js index 75ab7438011..d7d50c4e34e 100644 --- a/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/jsx/tsxUnionTypeComponent1x/input.tsx/es5.2.minified/output.js @@ -22,26 +22,43 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, React = require("react"), MyComponent = function(_Component) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var React = require("react"), MyComponent = function(_Component) { "use strict"; - var Constructor, protoProps, staticProps; + _inherits(MyComponent, _Component); + var Constructor, protoProps, staticProps, _super = _createSuper(MyComponent); function MyComponent() { - return _classCallCheck(this, MyComponent), _possibleConstructorReturn(this, _getPrototypeOf(MyComponent).apply(this, arguments)); + return _classCallCheck(this, MyComponent), _super.apply(this, arguments); } - return _inherits(MyComponent, _Component), Constructor = MyComponent, protoProps = [ + return Constructor = MyComponent, protoProps = [ { key: "render", value: function() { @@ -58,10 +75,12 @@ React.createElement(MyComponent, { }); var MyButtonComponent = function(_Component) { "use strict"; + _inherits(MyButtonComponent, _Component); + var _super = _createSuper(MyButtonComponent); function MyButtonComponent() { - return _classCallCheck(this, MyButtonComponent), _possibleConstructorReturn(this, _getPrototypeOf(MyButtonComponent).apply(this, arguments)); + return _classCallCheck(this, MyButtonComponent), _super.apply(this, arguments); } - return _inherits(MyButtonComponent, _Component), MyButtonComponent; + return MyButtonComponent; }(React.Component); React.createElement(MyComponent, { AnyComponent: MyButtonComponent diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.1.normal/output.js index d237297f51d..1d623ca058f 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.2.minified/output.js index 22315e66c1c..e0259d45350 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts1/input.ts/es5.2.minified/output.js @@ -10,16 +10,7 @@ function _setPrototypeOf(o, p) { } var C = function(A) { "use strict"; - function C() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -28,5 +19,35 @@ var C = function(A) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, A), C; + }(C, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, C), _super.apply(this, arguments); + } + return C; }(A); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.1.normal/output.js index 6a5af975de9..e1dd4fa3473 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.1.normal/output.js @@ -44,12 +44,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function(A) { "use strict"; _inherits(C, A); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(A); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.2.minified/output.js index 22315e66c1c..e0259d45350 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/Generics/parserGenericsInTypeContexts2/input.ts/es5.2.minified/output.js @@ -10,16 +10,7 @@ function _setPrototypeOf(o, p) { } var C = function(A) { "use strict"; - function C() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -28,5 +19,35 @@ var C = function(A) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, A), C; + }(C, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, C), _super.apply(this, arguments); + } + return C; }(A); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.1.normal/output.js index da411a4f850..5c9b61a9a2c 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var c1 = /*#__PURE__*/ function() { "use strict"; function c1() { @@ -195,11 +220,12 @@ var c2 = /*#__PURE__*/ function() { var c3 = /*#__PURE__*/ function(c2) { "use strict"; _inherits(c3, c2); + var _super = _createSuper(c3); function c3() { _classCallCheck(this, c3); - var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(c3).call(this, 10)); - _this.p1 = _get(_getPrototypeOf(c3.prototype), "c2_p1", _assertThisInitialized(_this)); + var _thisSuper, _this; + _this = _super.call(this, 10); + _this.p1 = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(c3.prototype)), "c2_p1", _thisSuper); return _this; } _createClass(c3, [ @@ -247,9 +273,10 @@ c2_i.nc_f1(); var c4 = /*#__PURE__*/ function(c2) { "use strict"; _inherits(c4, c2); + var _super = _createSuper(c4); function c4() { _classCallCheck(this, c4); - return _possibleConstructorReturn(this, _getPrototypeOf(c4).apply(this, arguments)); + return _super.apply(this, arguments); } return c4; }(c2); @@ -289,11 +316,12 @@ var c5 = function c5() { var c6 = /*#__PURE__*/ function(c5) { "use strict"; _inherits(c6, c5); + var _super = _createSuper(c6); function c6() { _classCallCheck(this, c6); - var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(c6).call(this)); - _this.d = _get(_getPrototypeOf(c6.prototype), "b", _assertThisInitialized(_this)); + var _thisSuper, _this; + _this = _super.call(this); + _this.d = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(c6.prototype)), "b", _thisSuper); return _this; } return c6; diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.2.minified/output.js index 30965b3dbb8..a2d76ac3c3c 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserAstSpans1/input.ts/es5.2.minified/output.js @@ -38,9 +38,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : _assertThisInitialized(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -50,9 +47,28 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var i1_i, i2_i, i3_i, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, c1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; +} +var i1_i, i2_i, i3_i, c1 = function() { "use strict"; function c1() { _classCallCheck(this, c1); @@ -136,11 +152,13 @@ var c2 = function() { ]), c2; }(), c3 = function(c2) { "use strict"; + _inherits(c3, c2); + var _super = _createSuper(c3); function c3() { - var _this; - return _classCallCheck(this, c3), (_this = _possibleConstructorReturn(this, _getPrototypeOf(c3).call(this, 10))).p1 = _get(_getPrototypeOf(c3.prototype), "c2_p1", _assertThisInitialized(_this)), _this; + var _thisSuper, _this; + return _classCallCheck(this, c3), (_this = _super.call(this, 10)).p1 = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(c3.prototype)), "c2_p1", _thisSuper), _this; } - return _inherits(c3, c2), _createClass(c3, [ + return _createClass(c3, [ { key: "f1", value: function() { @@ -168,10 +186,12 @@ var c2 = function() { c2_i.c2_f1(), c2_i.c2_nc_f1(), c2_i.f1(), c2_i.nc_f1(), c3_i.c2_f1(), c3_i.c2_nc_f1(), c3_i.f1(), c3_i.nc_f1(), (c2_i = c3_i).c2_f1(), c2_i.c2_nc_f1(), c2_i.f1(), c2_i.nc_f1(); var c4 = function(c2) { "use strict"; + _inherits(c4, c2); + var _super = _createSuper(c4); function c4() { - return _classCallCheck(this, c4), _possibleConstructorReturn(this, _getPrototypeOf(c4).apply(this, arguments)); + return _classCallCheck(this, c4), _super.apply(this, arguments); } - return _inherits(c4, c2), c4; + return c4; }(c2); new c4(10), i2_i.i2_f1(), i2_i.i2_nc_f1(), i2_i.f1(), i2_i.nc_f1(), i2_i.i2_l1(), i2_i.i2_nc_l1(), i2_i.l1(), i2_i.nc_l1(), i3_i.i2_f1(), i3_i.i2_nc_f1(), i3_i.f1(), i3_i.nc_f1(), i3_i.i2_l1(), i3_i.i2_nc_l1(), i3_i.l1(), i3_i.nc_l1(), (i2_i = i3_i).i2_f1(), i2_i.i2_nc_f1(), i2_i.f1(), i2_i.nc_f1(), i2_i.i2_l1(), i2_i.i2_nc_l1(), i2_i.l1(), i2_i.nc_l1(); var c51 = function() { @@ -179,9 +199,11 @@ var c51 = function() { _classCallCheck(this, c51); }, c6 = function(c5) { "use strict"; + _inherits(c6, c5); + var _super = _createSuper(c6); function c6() { - var _this; - return _classCallCheck(this, c6), (_this = _possibleConstructorReturn(this, _getPrototypeOf(c6).call(this))).d = _get(_getPrototypeOf(c6.prototype), "b", _assertThisInitialized(_this)), _this; + var _thisSuper, _this; + return _classCallCheck(this, c6), (_this = _super.call(this)).d = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(c6.prototype)), "b", _thisSuper), _this; } - return _inherits(c6, c5), c6; + return c6; }(c51); diff --git a/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.1.normal/output.js index b7ad93fc2d0..271aef99057 100644 --- a/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @noEmit: true // @allowJs: true // @checkJs: true @@ -106,10 +131,11 @@ var Sql = // ok /*#__PURE__*/ function(Wagon) { "use strict"; _inherits(Sql, Wagon); + var _super = _createSuper(Sql); function Sql() { _classCallCheck(this, Sql); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Sql).call(this)); // error: not enough arguments + _this = _super.call(this); // error: not enough arguments _this.foonly = 12; return _this; } @@ -140,9 +166,10 @@ var Drakkhen = // error, can't extend a TS constructor function /*#__PURE__*/ function(Dragon) { "use strict"; _inherits(Drakkhen, Dragon); + var _super = _createSuper(Drakkhen); function Drakkhen() { _classCallCheck(this, Drakkhen); - return _possibleConstructorReturn(this, _getPrototypeOf(Drakkhen).apply(this, arguments)); + return _super.apply(this, arguments); } return Drakkhen; }(Dragon1); @@ -156,9 +183,10 @@ var Firedrake = // error! /*#__PURE__*/ function(Dragon) { "use strict"; _inherits(Firedrake, Dragon); + var _super = _createSuper(Firedrake); function Firedrake() { _classCallCheck(this, Firedrake); - return _possibleConstructorReturn(this, _getPrototypeOf(Firedrake).call(this)); + return _super.call(this); } return Firedrake; }(Dragon1); @@ -166,10 +194,11 @@ var Conestoga = // ok /*#__PURE__*/ function(Wagon) { "use strict"; _inherits(Conestoga, Wagon); + var _super = _createSuper(Conestoga); function Conestoga(drunkOO) { _classCallCheck(this, Conestoga); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Conestoga).call(this, 'nope')); + _this = _super.call(this, 'nope'); _this.drunkOO = drunkOO; return _this; } @@ -197,9 +226,10 @@ c.numberOxen; var Chowder = /** @extends {Soup<{ claim: "ignorant" | "malicious" }>} */ /*#__PURE__*/ function(Soup) { "use strict"; _inherits(Chowder, Soup); + var _super = _createSuper(Chowder); function Chowder() { _classCallCheck(this, Chowder); - return _possibleConstructorReturn(this, _getPrototypeOf(Chowder).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Chowder, [ { diff --git a/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.2.minified/output.js index 8f36980973d..4640d2344c9 100644 --- a/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/classCanExtendConstructorFunction/input.ts/es5.2.minified/output.js @@ -34,12 +34,6 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -49,9 +43,30 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} function Wagon1(numberOxen) { this.numberOxen = numberOxen; } @@ -65,11 +80,13 @@ Wagon1.circle = function(wagons) { }; var Sql = function(Wagon) { "use strict"; + _inherits(Sql, Wagon); + var _super = _createSuper(Sql); function Sql() { var _this; - return _classCallCheck(this, Sql), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Sql).call(this))).foonly = 12, _this; + return _classCallCheck(this, Sql), (_this = _super.call(this)).foonly = 12, _this; } - return _inherits(Sql, Wagon), _createClass(Sql, [ + return _createClass(Sql, [ { key: "load", value: function(files, format) { @@ -82,27 +99,33 @@ var Sql = function(Wagon) { db.numberOxen = db.foonly; var Drakkhen = function(Dragon) { "use strict"; + _inherits(Drakkhen, Dragon); + var _super = _createSuper(Drakkhen); function Drakkhen() { - return _classCallCheck(this, Drakkhen), _possibleConstructorReturn(this, _getPrototypeOf(Drakkhen).apply(this, arguments)); + return _classCallCheck(this, Drakkhen), _super.apply(this, arguments); } - return _inherits(Drakkhen, Dragon), Drakkhen; + return Drakkhen; }(Dragon1); function Dragon1(numberEaten) { this.numberEaten = numberEaten; } var Firedrake = function(Dragon) { "use strict"; + _inherits(Firedrake, Dragon); + var _super = _createSuper(Firedrake); function Firedrake() { - return _classCallCheck(this, Firedrake), _possibleConstructorReturn(this, _getPrototypeOf(Firedrake).call(this)); + return _classCallCheck(this, Firedrake), _super.call(this); } - return _inherits(Firedrake, Dragon), Firedrake; + return Firedrake; }(Dragon1), Conestoga = function(Wagon) { "use strict"; + _inherits(Conestoga, Wagon); + var _super = _createSuper(Conestoga); function Conestoga(drunkOO) { var _this; - return _classCallCheck(this, Conestoga), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Conestoga).call(this, "nope"))).drunkOO = drunkOO, _this; + return _classCallCheck(this, Conestoga), (_this = _super.call(this, "nope")).drunkOO = drunkOO, _this; } - return _inherits(Conestoga, Wagon), _createClass(Conestoga, null, [ + return _createClass(Conestoga, null, [ { key: "circle", value: function(others) { @@ -117,10 +140,12 @@ function Soup1(flavour) { c.drunkOO, c.numberOxen; var Chowder = function(Soup) { "use strict"; + _inherits(Chowder, Soup); + var _super = _createSuper(Chowder); function Chowder() { - return _classCallCheck(this, Chowder), _possibleConstructorReturn(this, _getPrototypeOf(Chowder).apply(this, arguments)); + return _classCallCheck(this, Chowder), _super.apply(this, arguments); } - return _inherits(Chowder, Soup), _createClass(Chowder, [ + return _createClass(Chowder, [ { key: "log", value: function() { diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.1.normal/output.js index d01a690dcf1..8bb80306fa1 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.1.normal/output.js @@ -58,19 +58,45 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); this.p = 1; }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "m", value: function m() { @@ -78,5 +104,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.2.minified/output.js index 01abed76aba..3f8b41c9145 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments3/input.ts/es5.2.minified/output.js @@ -20,17 +20,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1), this.p = 1; -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - var Constructor, protoProps, staticProps; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,12 +31,40 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), protoProps = [ + }(Derived1, Base); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return protoProps = [ { key: "m", value: function() { this.p = 1; } } - ], _defineProperties((Constructor = Derived).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Derived; + ], _defineProperties((Constructor = Derived1).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.1.normal/output.js index 82a3bbbd152..ec80622a6db 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @noEmit: true // @allowJs: true // @checkJs: true @@ -79,14 +104,15 @@ var Base = // @noEmit: true ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "m", value: function m() { @@ -95,5 +121,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.2.minified/output.js index 8d04c17f81e..7d76c58749a 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments4/input.ts/es5.2.minified/output.js @@ -33,16 +33,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,12 +44,40 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return _createClass(Derived1, [ { key: "m", value: function() { this.p = 1; } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.1.normal/output.js index c25c7f643c6..f14a4201057 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = // @noEmit: true // @allowJs: true // @checkJs: true @@ -79,18 +104,19 @@ var Base = // @noEmit: true ]); return Base; }(); -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).call(this)); + _this = _super.call(this); // should be OK, and p should have type number from this assignment _this.p = 1; return _this; } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "test", value: function test() { @@ -98,5 +124,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.2.minified/output.js index a3f1a5ed61f..3f2e6d48fad 100644 --- a/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/inferringClassMembersFromAssignments5/input.ts/es5.2.minified/output.js @@ -33,16 +33,9 @@ var Base = function() { } } ]), Base; -}(), Derived = function(Base) { +}(), Derived1 = function(Base) { "use strict"; - function Derived() { - var _this, self, call, obj; - return _classCallCheck(this, Derived), (_this = (self = this, (call = _getPrototypeOf(Derived).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).p = 1, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,12 +44,41 @@ var Base = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + var _this; + return _classCallCheck(this, Derived1), (_this = _super.call(this)).p = 1, _this; + } + return _createClass(Derived1, [ { key: "test", value: function() { return this.p; } } - ]), Derived; + ]), Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.1.normal/output.js index 341e5cf735e..94b0470ef00 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _this = this; var B = // @noEmit: true // @checkJs: true @@ -81,9 +106,10 @@ var B = // @noEmit: true var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); @@ -93,9 +119,10 @@ C.prototype.foo = function() { var D = /*#__PURE__*/ function(B) { "use strict"; _inherits(D, B); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(B); @@ -111,9 +138,10 @@ Module.prototype.size = null; var NormalModule = /*#__PURE__*/ function(Module) { "use strict"; _inherits(NormalModule, Module); + var _super = _createSuper(NormalModule); function NormalModule() { _classCallCheck(this, NormalModule); - return _possibleConstructorReturn(this, _getPrototypeOf(NormalModule).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(NormalModule, [ { diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.2.minified/output.js index a2c3c147977..16de23c1126 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment23/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _this = this, B = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var _this = this, B = function() { "use strict"; function B() { _classCallCheck(this, B), this.n = 1; @@ -52,19 +68,23 @@ var _typeof = function(obj) { ]), B; }(), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), C; + return C; }(B); C.prototype.foo = function() { }; var D = function(B) { "use strict"; + _inherits(D, B); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, B), D; + return D; }(B); D.prototype.foo = function() { _this.n = "not checked, so no error"; @@ -76,10 +96,12 @@ var Module1 = function() { Module1.prototype.identifier = void 0, Module1.prototype.size = null; var NormalModule = function(Module) { "use strict"; + _inherits(NormalModule, Module); + var _super = _createSuper(NormalModule); function NormalModule() { - return _classCallCheck(this, NormalModule), _possibleConstructorReturn(this, _getPrototypeOf(NormalModule).apply(this, arguments)); + return _classCallCheck(this, NormalModule), _super.apply(this, arguments); } - return _inherits(NormalModule, Module), _createClass(NormalModule, [ + return _createClass(NormalModule, [ { key: "identifier", value: function() { diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.1.normal/output.js index 085a22fee44..810118987ac 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @noEmit: true // @checkJs: true // @allowJs: true @@ -58,10 +83,11 @@ Common.I = function _class() { Common.O = /*#__PURE__*/ (function(_I) { "use strict"; _inherits(_class, _I); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(_class).call(this)); + _this = _super.call(this); _this.o = 2; return _this; } diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.2.minified/output.js index 4c6bf93c115..b3f2fe08139 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment25/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ Common.I = function _class() { _classCallCheck(this, _class), this.i = 1; }, Common.O = (function(_I) { "use strict"; - function _class() { - var _this, self, call, obj; - return _classCallCheck(this, _class), (_this = (self = this, (call = _getPrototypeOf(_class).call(this)) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self))).o = 2, _this; - } - return (function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,7 +27,36 @@ Common.I = function _class() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - })(_class, _I), _class; + }(_class, _I); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(_class); + function _class() { + var _this; + return _classCallCheck(this, _class), (_this = _super.call(this)).o = 2, _this; + } + return _class; })(Common.I); var o1 = new Common.O(), i = new Common.I(); o1.i, o1.o, i.i; diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.1.normal/output.js index afee1ac5cc4..59440acb025 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @noEmit: true // @noImplicitAny: true // @checkJs: true @@ -74,9 +99,10 @@ UI.context = new UI.TreeElement(); var C = /*#__PURE__*/ function(_TreeElement) { "use strict"; _inherits(C, _TreeElement); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.2.minified/output.js index 636ca7e2402..81cf2d8e059 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignment26/input.ts/es5.2.minified/output.js @@ -25,15 +25,7 @@ UI.TreeElement = function _class() { }, UI.context = new UI.TreeElement(); var C = function(_TreeElement) { "use strict"; - var Constructor, protoProps, staticProps; - function C() { - var self, call, obj; - return _classCallCheck(this, C), self = this, call = _getPrototypeOf(C).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -42,7 +34,35 @@ var C = function(_TreeElement) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C, _TreeElement), protoProps = [ + }(C, _TreeElement); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C); + function C() { + return _classCallCheck(this, C), _super.apply(this, arguments); + } + return protoProps = [ { key: "onpopulate", value: function() { diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.1.normal/output.js index 5ab132af270..1a235c718c8 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @noEmit: true // @allowJs: true // @checkJs: true @@ -56,18 +81,20 @@ First.Item = function I() { Common.Object = /*#__PURE__*/ (function(_Item) { "use strict"; _inherits(_class, _Item); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; })(First.Item); Workspace.Object = /*#__PURE__*/ (function(_Object) { "use strict"; _inherits(_class, _Object); + var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); - return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _super.apply(this, arguments); } return _class; })(Common.Object); diff --git a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.2.minified/output.js index 564fff59d01..c4a12494f5f 100644 --- a/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/salsa/typeFromPropertyAssignmentOutOfOrder/input.ts/es5.2.minified/output.js @@ -16,35 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} First.Item = function I() { "use strict"; _classCallCheck(this, I); }, Common.Object = (function(_Item) { "use strict"; + _inherits(_class, _Item); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, _Item), _class; + return _class; })(First.Item), Workspace.Object = (function(_Object) { "use strict"; + _inherits(_class, _Object); + var _super = _createSuper(_class); function _class() { - return _classCallCheck(this, _class), _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments)); + return _classCallCheck(this, _class), _super.apply(this, arguments); } - return _inherits(_class, _Object), _class; + return _class; })(Common.Object); var First = { }, Common = { diff --git a/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.1.normal/output.js index d222c11db15..bce835828d1 100644 --- a/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var C2 = /*#__PURE__*/ function(C) { "use strict"; _inherits(C2, C); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(C); diff --git a/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.2.minified/output.js index c31ff0ee41d..acb5df2aae8 100644 --- a/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/VariableStatements/invalidMultipleVariableDeclarations/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var M1, C1 = function() { _classCallCheck(this, C1); }, C2 = function(C) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var M1, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C), C2; + }(C2, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return C2; }(C1), D = function() { "use strict"; _classCallCheck(this, D); diff --git a/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.1.normal/output.js index 159828b355d..e4e2c3b33a6 100644 --- a/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.1.normal/output.js @@ -81,6 +81,31 @@ function _superPropBase(object, property) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var aString; for(aString in { }){ @@ -168,9 +193,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.2.minified/output.js index ac3c777358a..d52adad68e2 100644 --- a/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/for-inStatements/for-inStatements/input.ts/es5.2.minified/output.js @@ -92,14 +92,7 @@ var Color, aString, anAny, c, d, e, i1, M1, Color1, A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -108,7 +101,35 @@ var Color, aString, anAny, c, d, e, i1, M1, Color1, A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "boz", value: function() { diff --git a/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.1.normal/output.js index ab72d975075..fef0b0ce743 100644 --- a/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var C2 = /*#__PURE__*/ function(C) { "use strict"; _inherits(C2, C); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(C); diff --git a/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.2.minified/output.js index 1c23b14f178..8b3f30e1ee6 100644 --- a/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/forStatements/forStatementsMultipleInvalidDecl/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var M1, C1 = function() { _classCallCheck(this, C1); }, C2 = function(C) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var M1, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C), C2; + }(C2, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return C2; }(C1), D = function() { "use strict"; _classCallCheck(this, D); diff --git a/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.1.normal/output.js index 5f56ee1b48b..1ee46de0b8a 100644 --- a/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var C2 = /*#__PURE__*/ function(C) { "use strict"; _inherits(C2, C); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(C); diff --git a/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.2.minified/output.js index 45887b78eca..b0640f28c5f 100644 --- a/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/ifDoWhileStatements/ifDoWhileStatements/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var M1, N1, C1 = function() { _classCallCheck(this, C1); }, C2 = function(C) { "use strict"; - function C2() { - var self, call, obj; - return _classCallCheck(this, C2), self = this, call = _getPrototypeOf(C2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var M1, N1, C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(C2, C), C2; + }(C2, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(C2); + function C2() { + return _classCallCheck(this, C2), _super.apply(this, arguments); + } + return C2; }(C1), D = function() { "use strict"; _classCallCheck(this, D); diff --git a/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.1.normal/output.js index 85882241948..b1c383ca766 100644 --- a/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // all the following should be error function fn1() { } @@ -86,9 +111,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.2.minified/output.js index 202c6923a40..e849e4e0357 100644 --- a/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/returnStatements/invalidReturnStatements/input.ts/es5.2.minified/output.js @@ -32,14 +32,7 @@ var C = function() { ], _defineProperties((Constructor = C).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -48,5 +41,33 @@ var C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C); diff --git a/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.1.normal/output.js index fc07a081fa1..76fbdc3a794 100644 --- a/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // all the following should be valid function fn1() { return 1; @@ -100,9 +125,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.2.minified/output.js index 202c6923a40..e849e4e0357 100644 --- a/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/returnStatements/returnStatements/input.ts/es5.2.minified/output.js @@ -32,14 +32,7 @@ var C = function() { ], _defineProperties((Constructor = C).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -48,5 +41,33 @@ var C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C); diff --git a/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.1.normal/output.js index c717b1f16d3..9ffa0a0d17e 100644 --- a/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var M1; (function(M) { var fn = function fn(x) { @@ -89,9 +114,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.2.minified/output.js index 56c7adfe1c8..bed780533d8 100644 --- a/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/statements/switchStatements/switchStatements/input.ts/es5.2.minified/output.js @@ -49,14 +49,7 @@ var C1 = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - function D() { - var self, call; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -65,7 +58,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); switch(new C1()){ case new D(): diff --git a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.1.normal/output.js index e44fe422b19..1b45718d2cf 100644 --- a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.2.minified/output.js index 9920048e5cb..74f0da8ca58 100644 --- a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceError/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var C1 = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); testError(function(t1, t2, t3) { }), testError(function(t1, t2, t3) { diff --git a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.1.normal/output.js index 1618c0c856f..d824a9c8579 100644 --- a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.2.minified/output.js index ec609aa75ab..4ad3859c196 100644 --- a/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionInferenceWithTypeParameter/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var C1 = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); test(function(t1, t2) { t2.test2; diff --git a/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.1.normal/output.js index 9940736a815..cddb3b40b55 100644 --- a/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.1.normal/output.js @@ -75,6 +75,31 @@ function _toConsumableArray(arr) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Shape = function Shape() { "use strict"; _classCallCheck(this, Shape); @@ -82,9 +107,10 @@ var Shape = function Shape() { var TaggedShape = /*#__PURE__*/ function(Shape) { "use strict"; _inherits(TaggedShape, Shape); + var _super = _createSuper(TaggedShape); function TaggedShape() { _classCallCheck(this, TaggedShape); - return _possibleConstructorReturn(this, _getPrototypeOf(TaggedShape).apply(this, arguments)); + return _super.apply(this, arguments); } return TaggedShape; }(Shape); @@ -433,10 +459,11 @@ var Base = // Repros from #12011 var Person = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Person, Base); + var _super = _createSuper(Person); function Person(parts) { _classCallCheck(this, Person); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Person).call(this)); + _this = _super.call(this); _this.set("parts", parts); return _this; } @@ -581,9 +608,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -619,12 +647,13 @@ var SampleClass = function SampleClass(props) { var AnotherSampleClass = /*#__PURE__*/ function(SampleClass) { "use strict"; _inherits(AnotherSampleClass, SampleClass); + var _super = _createSuper(AnotherSampleClass); function AnotherSampleClass(props) { _classCallCheck(this, AnotherSampleClass); var foo = { foo: "bar" }; - return _possibleConstructorReturn(this, _getPrototypeOf(AnotherSampleClass).call(this, merge(props, foo))); + return _super.call(this, merge(props, foo)); } _createClass(AnotherSampleClass, [ { diff --git a/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.2.minified/output.js index f40054166b8..04ba9a4d46c 100644 --- a/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/keyof/keyofAndIndexedAccess/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Flag, E, Flag1, E1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Shape1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Flag, E, Flag1, E1, Shape1 = function() { "use strict"; _classCallCheck(this, Shape1); }, TaggedShape = function(Shape) { "use strict"; + _inherits(TaggedShape, Shape); + var _super = _createSuper(TaggedShape); function TaggedShape() { - return _classCallCheck(this, TaggedShape), _possibleConstructorReturn(this, _getPrototypeOf(TaggedShape).apply(this, arguments)); + return _classCallCheck(this, TaggedShape), _super.apply(this, arguments); } - return _inherits(TaggedShape, Shape), TaggedShape; + return TaggedShape; }(Shape1), Item = function() { "use strict"; _classCallCheck(this, Item); @@ -130,11 +148,13 @@ var Component = function() { ]), Base; }(), Person = function(Base) { "use strict"; + _inherits(Person, Base); + var _super = _createSuper(Person); function Person(parts) { var _this; - return _classCallCheck(this, Person), (_this = _possibleConstructorReturn(this, _getPrototypeOf(Person).call(this))).set("parts", parts), _this; + return _classCallCheck(this, Person), (_this = _super.call(this)).set("parts", parts), _this; } - return _inherits(Person, Base), _createClass(Person, [ + return _createClass(Person, [ { key: "getParts", value: function() { @@ -176,10 +196,12 @@ var A1 = function() { _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "f", value: function(p) { @@ -205,12 +227,14 @@ var A1 = function() { _classCallCheck(this, SampleClass1), this.props = Object.freeze(props); }, AnotherSampleClass = function(SampleClass) { "use strict"; + _inherits(AnotherSampleClass, SampleClass); + var _super = _createSuper(AnotherSampleClass); function AnotherSampleClass(props) { - return _classCallCheck(this, AnotherSampleClass), _possibleConstructorReturn(this, _getPrototypeOf(AnotherSampleClass).call(this, merge(props, { + return _classCallCheck(this, AnotherSampleClass), _super.call(this, merge(props, { foo: "bar" - }))); + })); } - return _inherits(AnotherSampleClass, SampleClass), _createClass(AnotherSampleClass, [ + return _createClass(AnotherSampleClass, [ { key: "brokenMethod", value: function() { diff --git a/crates/swc/tests/tsc-references/types/localTypes/localTypes1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/localTypes/localTypes1/input.ts/es5.1.normal/output.js index ccf2589e56a..82eae88f4a7 100644 --- a/crates/swc/tests/tsc-references/types/localTypes/localTypes1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/localTypes/localTypes1/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // @target: es5 function f1() { (function(E) { @@ -213,9 +238,10 @@ function f6() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A2); @@ -223,9 +249,10 @@ function f6() { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(B); diff --git a/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.1.normal/output.js index 99e00354f50..dc1e8234b28 100644 --- a/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // accessing any protected outside the class is an error /*#__PURE__*/ function() { "use strict"; @@ -92,9 +117,10 @@ C.g = function() { var D = /*#__PURE__*/ function(C1) { "use strict"; _inherits(D, C1); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.2.minified/output.js index 0bb3ab83e83..f73559e551f 100644 --- a/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/members/classWithProtectedProperty/input.ts/es5.2.minified/output.js @@ -48,14 +48,7 @@ C.g = function() { }; var D = function(C1) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -64,7 +57,35 @@ var D = function(C1) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C1), _createClass(D, [ + }(D, C1); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "method", value: function() { diff --git a/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.1.normal/output.js index 7a7fc6b39c0..3e91851b28e 100644 --- a/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -65,9 +90,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.2.minified/output.js index 4ffb0952e8c..0aa830e99a7 100644 --- a/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/members/objectTypeHidingMembersOfExtendedObject/input.ts/es5.2.minified/output.js @@ -22,14 +22,7 @@ var c, i1, b, A1 = function() { _classCallCheck(this, A1); }, B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -38,7 +31,35 @@ var c, i1, b, A1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return B; }(A1), C = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.1.normal/output.js index 674fab14338..35f152d892e 100644 --- a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -65,18 +90,20 @@ var Base = function Base() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.2.minified/output.js index 0f6350a2b49..9c0aa94627c 100644 --- a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedCallSignatures/input.ts/es5.2.minified/output.js @@ -22,34 +22,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var i1, a, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var i1, a, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1), C = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.1.normal/output.js index 8aa334ec475..0fb9c7ee028 100644 --- a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -51,18 +76,20 @@ var Base = function Base() { var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.2.minified/output.js index 5b3a4e46107..c14243294aa 100644 --- a/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/members/typesWithSpecializedConstructSignatures/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var i, a, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var i, a, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived1 = function(Base) { "use strict"; + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base), Derived1; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1), C = function(x) { return _classCallCheck(this, C), x; }; diff --git a/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.1.normal/output.js index c2f3e7c6ac5..aa87cc3b874 100644 --- a/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} function test1(x) { x.a; x.b; @@ -110,17 +135,18 @@ var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.a = 1; return _this; } - _createClass(Derived, [ + _createClass(Derived1, [ { key: "f", value: function f() { @@ -128,5 +154,5 @@ var Derived = /*#__PURE__*/ function(Base) { } } ]); - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.2.minified/output.js index e0688a3fbf0..c0ad186ed9e 100644 --- a/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/namedTypes/optionalMethods/input.ts/es5.2.minified/output.js @@ -42,16 +42,9 @@ var Bar = function() { }(), Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var _this, self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self)).a = 1, _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -60,12 +53,41 @@ var Bar = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), _createClass(Derived, [ + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + var _this; + return _classCallCheck(this, Derived1), _this = _super.apply(this, arguments), _this.a = 1, _this; + } + return _createClass(Derived1, [ { key: "f", value: function() { return 1; } } - ]), Derived; + ]), Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js index d5ca6c3873f..c22375054ae 100644 --- a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // String indexer providing a constraint of a user defined type /*#__PURE__*/ function() { "use strict"; @@ -77,9 +102,10 @@ var A = // String indexer providing a constraint of a user defined type var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js index a994fd57ecd..58451e62926 100644 --- a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js index 6e2f0d5ed51..7ee6b4f443a 100644 --- a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // String indexer providing a constraint of a user defined type /*#__PURE__*/ function() { "use strict"; @@ -77,9 +102,10 @@ var A = // String indexer providing a constraint of a user defined type var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js index ff70c0d0ea8..ef5841e9c8d 100644 --- a/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.1.normal/output.js index 759d34c1d95..db733310522 100644 --- a/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C(x) { @@ -80,9 +105,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.2.minified/output.js index 22e80bb090c..e3277073c77 100644 --- a/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/specifyingTypes/typeQueries/typeofClass2/input.ts/es5.2.minified/output.js @@ -39,14 +39,7 @@ var C = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -55,7 +48,35 @@ var C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return _createClass(D, [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.1.normal/output.js index 4cd80eb29d5..f4167b775f3 100644 --- a/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -76,9 +101,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { @@ -93,9 +119,10 @@ var B = /*#__PURE__*/ function(A) { var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.2.minified/output.js index 903ea1eb64c..06fb81483a4 100644 --- a/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/fluentClasses/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var c, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var c, A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -53,10 +69,12 @@ var c, _typeof = function(obj) { ]), A; }(), B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), _createClass(B, [ + return _createClass(B, [ { key: "bar", value: function() { @@ -66,10 +84,12 @@ var c, _typeof = function(obj) { ]), B; }(A), C = function(B) { "use strict"; + _inherits(C, B); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, B), _createClass(C, [ + return _createClass(C, [ { key: "baz", value: function() { diff --git a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.1.normal/output.js index 665fae608fa..c280aab9f71 100644 --- a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var _this = this, _this1 = this, _this2 = this, _this3 = this, _this4 = this; var B = function B() { "use strict"; @@ -99,9 +124,10 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); @@ -292,9 +318,10 @@ var Base1 = // class-based assignability var Derived1 = /*#__PURE__*/ function(Base1) { "use strict"; _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); function Derived1() { _classCallCheck(this, Derived1); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived1; }(Base1); @@ -322,9 +349,10 @@ var Base2 = /*#__PURE__*/ function() { var Derived2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.2.minified/output.js index d0903b5bbfb..8e58bac515c 100644 --- a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var explicitCFunction, explicitPropertyFunction, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, _this = this, _this1 = this, _this2 = this, _this3 = this, B = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var explicitCFunction, explicitPropertyFunction, _this = this, _this1 = this, _this2 = this, _this3 = this, B = function() { "use strict"; _classCallCheck(this, B); }, C = function() { @@ -74,10 +90,12 @@ var explicitCFunction, explicitPropertyFunction, _typeof = function(obj) { ]), C; }(), D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), D; + return D; }(C); function implicitThis(n) { return this.m + n + 12; @@ -191,10 +209,12 @@ var Base1 = function() { ]), Base1; }(), Derived1 = function(Base1) { "use strict"; + _inherits(Derived1, Base1); + var _super = _createSuper(Derived1); function Derived1() { - return _classCallCheck(this, Derived1), _possibleConstructorReturn(this, _getPrototypeOf(Derived1).apply(this, arguments)); + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived1, Base1), Derived1; + return Derived1; }(Base1), Base2 = function() { "use strict"; function Base2() { @@ -216,10 +236,12 @@ var Base1 = function() { ]), Base2; }(), Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base2), b1 = new Base1(), b2 = new Base2(), d1 = new Derived1(), d2 = new Derived2(); d2.polymorphic = d1.polymorphic, d1.polymorphic = d2.polymorphic, d1.polymorphic = b2.polymorphic, d2.polymorphic = d1.explicit, b1.polymorphic = d2.polymorphic, b1.explicit = d2.polymorphic, new function() { this.a = 12; diff --git a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.1.normal/output.js index 675bb653512..6bda09a6f17 100644 --- a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.1.normal/output.js @@ -58,12 +58,38 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Test = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Test, Base); + var _super = _createSuper(Test); function Test() { _classCallCheck(this, Test); - return _possibleConstructorReturn(this, _getPrototypeOf(Test).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(Test, [ { diff --git a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.2.minified/output.js index 52c239fa69c..a4908300f33 100644 --- a/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/thisTypeInFunctions3/input.ts/es5.2.minified/output.js @@ -16,17 +16,7 @@ function _setPrototypeOf(o, p) { } var Test = function(Base) { "use strict"; - var Constructor, protoProps, staticProps; - function Test() { - var self, call, obj; - return !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Test), self = this, call = _getPrototypeOf(Test).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -35,7 +25,37 @@ var Test = function(Base) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Test, Base), protoProps = [ + }(Test, Base); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Test); + function Test() { + return !function(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); + }(this, Test), _super.apply(this, arguments); + } + return protoProps = [ { key: "m", value: function() { diff --git a/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.1.normal/output.js index d459ca9f6e7..7e905eaa8a1 100644 --- a/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = /*#__PURE__*/ function() { "use strict"; function C() { @@ -108,10 +133,11 @@ var C = /*#__PURE__*/ function() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.self1 = _assertThisInitialized(_this); _this.self2 = _this.self; _this.self3 = _this.foo(); diff --git a/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.2.minified/output.js index f8463913495..7c4b6722935 100644 --- a/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/thisType/typeRelationships/input.ts/es5.2.minified/output.js @@ -57,11 +57,7 @@ var C = function() { ]), C; }(), D = function(C) { "use strict"; - function D() { - var _this, self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), (_this = call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self)).self1 = _assertThisInitialized(_this), _this.self2 = _this.self, _this.self3 = _this.foo(), _this.d = new D(), _this; - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -70,7 +66,33 @@ var C = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), _createClass(D, [ + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + }; + }(D); + function D() { + var _this; + return _classCallCheck(this, D), _this = _super.apply(this, arguments), _this.self1 = _assertThisInitialized(_this), _this.self2 = _this.self, _this.self3 = _this.foo(), _this.d = new D(), _this; + } + return _createClass(D, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.1.normal/output.js index d0c7ef58913..373574caa15 100644 --- a/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -60,18 +85,20 @@ var D = function D() { var E = /*#__PURE__*/ function(A) { "use strict"; _inherits(E, A); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } return E; }(A); var F = /*#__PURE__*/ function(A) { "use strict"; _inherits(F, A); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); - return _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _super.apply(this, arguments); } return F; }(A); diff --git a/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.2.minified/output.js index 0486b8effef..6648f3ac352 100644 --- a/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/tuple/castingTuple/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var E1, E2, E11, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var E1, E2, E11, A1 = function() { "use strict"; _classCallCheck(this, A1), this.a = 10; }, C = function() { @@ -40,16 +56,20 @@ var E1, E2, E11, _typeof = function(obj) { _classCallCheck(this, D); }, E = function(A) { "use strict"; + _inherits(E, A); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, A), E; + return E; }(A1), F = function(A) { "use strict"; + _inherits(F, A); + var _super = _createSuper(F); function F() { - return _classCallCheck(this, F), _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _classCallCheck(this, F), _super.apply(this, arguments); } - return _inherits(F, A), F; + return F; }(A1); (E11 = E1 || (E1 = { }))[E11.one = 0] = "one", (E21 = E2 || (E2 = { diff --git a/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.1.normal/output.js index b71f81cade3..961b9722fac 100644 --- a/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var StringTreeCollectionBase = function StringTreeCollectionBase() { "use strict"; _classCallCheck(this, StringTreeCollectionBase); @@ -51,9 +76,10 @@ var StringTreeCollectionBase = function StringTreeCollectionBase() { var StringTreeCollection = /*#__PURE__*/ function(StringTreeCollectionBase) { "use strict"; _inherits(StringTreeCollection, StringTreeCollectionBase); + var _super = _createSuper(StringTreeCollection); function StringTreeCollection() { _classCallCheck(this, StringTreeCollection); - return _possibleConstructorReturn(this, _getPrototypeOf(StringTreeCollection).apply(this, arguments)); + return _super.apply(this, arguments); } return StringTreeCollection; }(StringTreeCollectionBase); diff --git a/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.2.minified/output.js index 5ae1035ede6..479e142a61a 100644 --- a/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeAliases/classDoesNotDependOnBaseTypes/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var x, StringTreeCollectionBase1 = function() { _classCallCheck(this, StringTreeCollectionBase1); }, StringTreeCollection = function(StringTreeCollectionBase) { "use strict"; - function StringTreeCollection() { - var self, call, obj; - return _classCallCheck(this, StringTreeCollection), self = this, call = _getPrototypeOf(StringTreeCollection).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,6 +25,34 @@ var x, StringTreeCollectionBase1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(StringTreeCollection, StringTreeCollectionBase), StringTreeCollection; + }(StringTreeCollection, StringTreeCollectionBase); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(StringTreeCollection); + function StringTreeCollection() { + return _classCallCheck(this, StringTreeCollection), _super.apply(this, arguments); + } + return StringTreeCollection; }(StringTreeCollectionBase1); "string" != typeof x && (x[0] = "", x[0] = new StringTreeCollection); diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.1.normal/output.js index 9b19833acd7..f1626de435a 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.1.normal/output.js @@ -44,23 +44,50 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = // type parameters cannot be used as base types // these are all errors /*#__PURE__*/ function(T) { "use strict"; _inherits(C, T); + var _super = _createSuper(C); function C() { _classCallCheck(this, C); - return _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _super.apply(this, arguments); } return C; }(T); var C2 = /*#__PURE__*/ function(U) { "use strict"; _inherits(C2, U); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(U); diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.2.minified/output.js index 0629e2e68f5..1eb040fa63f 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterAsBaseType/input.ts/es5.2.minified/output.js @@ -16,29 +16,49 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function(T) { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function(T) { "use strict"; + _inherits(C, T); + var _super = _createSuper(C); function C() { - return _classCallCheck(this, C), _possibleConstructorReturn(this, _getPrototypeOf(C).apply(this, arguments)); + return _classCallCheck(this, C), _super.apply(this, arguments); } - return _inherits(C, T), C; + return C; }(T), C2 = function(U) { "use strict"; + _inherits(C2, U); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, U), C2; + return C2; }(U); diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.1.normal/output.js index 8e8fd9252bd..f457e35ffdc 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // generic types should behave as if they have properties of their constraint type /*#__PURE__*/ function() { "use strict"; @@ -77,9 +102,10 @@ var A = // generic types should behave as if they have properties of their const var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.2.minified/output.js index b3a5eccf5a5..95dbc8471b9 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints2/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var i1, a, A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var i1, a, A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.1.normal/output.js index 02845147dfc..c8c7e0dc642 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = // generic types should behave as if they have properties of their constraint type /*#__PURE__*/ function() { "use strict"; @@ -77,9 +102,10 @@ var A = // generic types should behave as if they have properties of their const var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.2.minified/output.js index 703d209a5a8..6ad1c8767ef 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var i1, a, A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var i1, a, A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.1.normal/output.js index 210223d0b0e..309eb70a9cb 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = /*#__PURE__*/ function() { "use strict"; function A() { @@ -76,9 +101,10 @@ var A = /*#__PURE__*/ function() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(B, [ { diff --git a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.2.minified/output.js index 641bdaf2395..726e354b348 100644 --- a/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints5/input.ts/es5.2.minified/output.js @@ -35,14 +35,7 @@ var i1, a, A = function() { ]), A; }(), B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -51,7 +44,35 @@ var i1, a, A = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B, A), _createClass(B, [ + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return _createClass(B, [ { key: "bar", value: function() { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.1.normal/output.js index d3724310d48..d461e80b7c2 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.1.normal/output.js @@ -44,19 +44,45 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = // is String (S) a subtype of U extends String (T)? Would only be true if we used the apparent type of U (T) +var Derived1 = // is String (S) a subtype of U extends String (T)? Would only be true if we used the apparent type of U (T) /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Base2 = function Base2() { "use strict"; @@ -66,9 +92,10 @@ var Derived2 = // is U extends String (S) a subtype of String (T)? Apparent type /*#__PURE__*/ function(Base2) { "use strict"; _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base2); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.2.minified/output.js index 7178777f07c..93de082aa66 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSubtyping/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Base21 = function() { "use strict"; _classCallCheck(this, Base21); }, Derived2 = function(Base2) { "use strict"; + _inherits(Derived2, Base2); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base2), Derived2; + return Derived2; }(Base21); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.1.normal/output.js index 48d1952c870..fb265ac133d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.1.normal/output.js @@ -44,17 +44,43 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = // is String (S) a subtype of U extends String (T)? Would only be true if we used the apparent type of U (T) +var Derived1 = // is String (S) a subtype of U extends String (T)? Would only be true if we used the apparent type of U (T) /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.2.minified/output.js index 35d40b513de..ee500ec9b01 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/apparentType/apparentTypeSupertype/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,5 +25,33 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.1.normal/output.js index 57b7f6a5d27..e5c9ab6b3c7 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.2.minified/output.js index 6f6e7532667..7f80a1ea3f4 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); b = b, b2 = b2, b3 = b3, b4 = b4, b5 = b5, b6 = b6, b7 = b7, b8 = b8, b9 = b9, b10 = b10, b11 = b11, b12 = b12, b13 = b13, b14 = b14, b15 = b15, b16 = b16, b17 = b17, b18 = b18; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.1.normal/output.js index a6d71bb3df4..511eaa67c09 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // These are mostly permitted with the current loose rules. All ok unless otherwise noted. var Errors; (function(Errors) { @@ -54,27 +79,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.2.minified/output.js index 0e1d58a8078..11982faeead 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var WithNonGenericSignaturesInBaseType, WithGenericSignaturesInBaseType, b2, b7, b8, b10, b11, b12, b15, b15a, b16, b17, b21, b3, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); WithNonGenericSignaturesInBaseType || (WithNonGenericSignaturesInBaseType = { }), b2 = b2, b7 = b7, b8 = b8, b10 = b10, b11 = b11, b12 = b12, b15 = b15, b15a = b15a, b16 = b16, b17 = b17, WithGenericSignaturesInBaseType || (WithGenericSignaturesInBaseType = { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.1.normal/output.js index 0821abf21c3..f2ab842720f 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.2.minified/output.js index 792054740d0..38cddcd2590 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var a16, b, b2, b3, b4, b5, b6, b11, b15, b17, b18, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var a16, b, b2, b3, b4, b5, b6, b11, b15, b17, b18, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); b = b, b2 = b2, b3 = b3, b4 = b4, b5 = b5, b6 = b6, b11 = b11, b15 = b15, b15 = a16, b17 = b17, b18 = b18; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.1.normal/output.js index a5fab82b8c7..4c17bfe9102 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.2.minified/output.js index 5b3cacef6cc..d78008687af 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x, b, b2, b3, b4, b5, b11, b16, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x, b, b2, b3, b4, b5, b11, b16, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); x.a = b, b = x.a, x.a2 = b2, b2 = x.a2, x.a3 = b3, b3 = x.a3, x.a4 = b4, b4 = x.a4, x.a5 = b5, b5 = x.a5, x.a11 = b11, b11 = x.a11, x.a16 = b16, b16 = x.a16; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.1.normal/output.js index 57b7f6a5d27..e5c9ab6b3c7 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.2.minified/output.js index 6f6e7532667..7f80a1ea3f4 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); b = b, b2 = b2, b3 = b3, b4 = b4, b5 = b5, b6 = b6, b7 = b7, b8 = b8, b9 = b9, b10 = b10, b11 = b11, b12 = b12, b13 = b13, b14 = b14, b15 = b15, b16 = b16, b17 = b17, b18 = b18; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.1.normal/output.js index b8888a8408b..17d09b2251d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // checking assignment compatibility relations for function types. var Errors; (function(Errors) { @@ -54,27 +79,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.2.minified/output.js index 0e1d58a8078..11982faeead 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var WithNonGenericSignaturesInBaseType, WithGenericSignaturesInBaseType, b2, b7, b8, b10, b11, b12, b15, b15a, b16, b17, b21, b3, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); WithNonGenericSignaturesInBaseType || (WithNonGenericSignaturesInBaseType = { }), b2 = b2, b7 = b7, b8 = b8, b10 = b10, b11 = b11, b12 = b12, b15 = b15, b15a = b15a, b16 = b16, b17 = b17, WithGenericSignaturesInBaseType || (WithGenericSignaturesInBaseType = { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.1.normal/output.js index dff24e71bc7..9eef04a0a76 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.2.minified/output.js index 792054740d0..38cddcd2590 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var a16, b, b2, b3, b4, b5, b6, b11, b15, b17, b18, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var a16, b, b2, b3, b4, b5, b6, b11, b15, b17, b18, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); b = b, b2 = b2, b3 = b3, b4 = b4, b5 = b5, b6 = b6, b11 = b11, b15 = b15, b15 = a16, b17 = b17, b18 = b18; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.1.normal/output.js index a5fab82b8c7..4c17bfe9102 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.2.minified/output.js index 5b3cacef6cc..d78008687af 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var x, b, b2, b3, b4, b5, b11, b16, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var x, b, b2, b3, b4, b5, b11, b16, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); x.a = b, b = x.a, x.a2 = b2, b2 = x.a2, x.a3 = b3, b3 = x.a3, x.a4 = b4, b4 = x.a4, x.a5 = b5, b5 = x.a5, x.a11 = b11, b11 = x.a11, x.a16 = b16, b16 = x.a16; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.1.normal/output.js index 9eeb1546989..637d80a12ad 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -76,9 +101,10 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.2.minified/output.js index 09aa14e694f..26b03c0cb2a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer/input.ts/es5.2.minified/output.js @@ -21,14 +21,7 @@ b = b, b2 = b2, (function(Generics) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; - function B() { - var self, call, obj; - return _classCallCheck(this, B), self = this, call = _getPrototypeOf(B).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return (function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -37,7 +30,35 @@ b = b, b2 = b2, (function(Generics) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - })(B, A), B; + }(B, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B); + function B() { + return _classCallCheck(this, B), _super.apply(this, arguments); + } + return B; }(A2); })(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.1.normal/output.js index 91fb20c85a0..79657ce38b3 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -55,9 +80,10 @@ b1 = a1; // ok var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.2.minified/output.js index 8c02e1204ec..49896a83ab9 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ var b, b2, Generics, A1 = function() { b = b; var B2 = function(A) { "use strict"; - function B2() { - var self, call, obj; - return _classCallCheck(this, B2), self = this, call = _getPrototypeOf(B2).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,7 +27,35 @@ var B2 = function(A) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(B2, A), B2; + }(B2, A); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(B2); + function B2() { + return _classCallCheck(this, B2), _super.apply(this, arguments); + } + return B2; }(A1); b2 = b2, (function(Generics) { var A = function() { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.1.normal/output.js index b42841a0c92..37210f52a2a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // members N and M of types S and T have the same name, same accessibility, same optionality, and N is not assignable M var OnlyDerived; (function(OnlyDerived) { @@ -54,18 +79,20 @@ var OnlyDerived; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); @@ -119,18 +146,20 @@ var WithBase; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.2.minified/output.js index be320eddde1..94cdcec8da4 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var OnlyDerived, WithBase; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,36 +17,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var OnlyDerived, WithBase, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(OnlyDerived) { var t, t2, b, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1), S = function() { "use strict"; _classCallCheck(this, S); @@ -65,16 +85,20 @@ var OnlyDerived, WithBase, _typeof = function(obj) { _classCallCheck(this, Base2); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base2), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base2), S = function() { "use strict"; _classCallCheck(this, S); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.1.normal/output.js index 8e625edecd6..ee28a0379b2 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.1.normal/output.js @@ -44,28 +44,55 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var TargetHasOptional; (function(TargetHasOptional) { var c; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.2.minified/output.js index 386d14352aa..21c97558ae8 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var TargetHasOptional, SourceHasOptional, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var TargetHasOptional, SourceHasOptional, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived); + return Derived2; +}(Derived1); !function(TargetHasOptional) { var c, a, d, e, f; new Base1(), c = d, c = e, c = f, c = a, a = d, a = e, a = f, a = c; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.1.normal/output.js index df6a37f8120..cd14592ee6a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.1.normal/output.js @@ -44,28 +44,55 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var TargetHasOptional; (function(TargetHasOptional) { var c; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.2.minified/output.js index 66ad6a1f651..919839892ec 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var TargetHasOptional, SourceHasOptional, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var TargetHasOptional, SourceHasOptional, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived); + return Derived2; +}(Derived1); TargetHasOptional || (TargetHasOptional = { }), new Base1(), (function(SourceHasOptional) { var c, a, d, e, f; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.1.normal/output.js index 95d7f7245be..06920ef5b7f 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -73,9 +98,10 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -86,9 +112,10 @@ var Generics; var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.2.minified/output.js index 7fb31cc63ca..e25ebac1a95 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, b21, Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, b21, Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }; @@ -39,18 +55,22 @@ b = b, b21 = b21, (function(Generics) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2); b1 = b1; var B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A2); b2 = b2; })(Generics || (Generics = { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js index dec0c7f1fd9..d98bd20fb6d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // checking subtype relations for function types as it relates to contextual signature instantiation // error cases var Errors; @@ -55,27 +80,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js index 902648ae3af..77021541b9f 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); }(Errors || (Errors = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance2/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js index dec0c7f1fd9..d98bd20fb6d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // checking subtype relations for function types as it relates to contextual signature instantiation // error cases var Errors; @@ -55,27 +80,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js index 902648ae3af..77021541b9f 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); }(Errors || (Errors = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance4/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance5/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.1.normal/output.js index 80f7f2b0736..bb0c4804505 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var unionNumberString; var C = function C() { "use strict"; @@ -66,9 +91,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { @@ -82,9 +108,10 @@ var D = /*#__PURE__*/ function(C) { var E = /*#__PURE__*/ function(C) { "use strict"; _inherits(E, C); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.2.minified/output.js index 62f0a40d792..c44840a3c14 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/unionTypesAssignability/input.ts/es5.2.minified/output.js @@ -25,28 +25,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var unionNumberString, unionDE, num, str, c, d, e, anyVar, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var unionNumberString, unionDE, num, str, c, d, e, anyVar, C1 = function() { "use strict"; _classCallCheck(this, C1); }, D = function(C) { "use strict"; + _inherits(D, C); + var _super = _createSuper(D); function D() { - return _classCallCheck(this, D), _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _classCallCheck(this, D), _super.apply(this, arguments); } - return _inherits(D, C), _createClass(D, [ + return _createClass(D, [ { key: "foo1", value: function() { @@ -55,10 +73,12 @@ var unionNumberString, unionDE, num, str, c, d, e, anyVar, _typeof = function(ob ]), D; }(C1), E = function(C) { "use strict"; + _inherits(E, C); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, C), _createClass(E, [ + return _createClass(E, [ { key: "foo2", value: function() { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.1.normal/output.js index 8f6e2b9fb42..39049b6edf3 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist) // no errors expected here var a; @@ -52,21 +77,23 @@ var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.2.minified/output.js index 8caeee4a6c4..2b9233bd7c9 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.1.normal/output.js index 7d3abc8c136..0a44f51121d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.2.minified/output.js index 8caeee4a6c4..2b9233bd7c9 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.1.normal/output.js index 998a52a13cb..3514ecc7d2c 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -59,9 +84,10 @@ var E = function E() { var F = /*#__PURE__*/ function(C) { "use strict"; _inherits(F, C); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); - return _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _super.apply(this, arguments); } return F; }(C); @@ -73,10 +99,11 @@ var C1 = function C1() { var D1 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(D1, C1); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); var _this; - _this = _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + _this = _super.apply(this, arguments); _this.i = "bar"; return _this; } diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.2.minified/output.js index c720d35fba6..a1b07daec65 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var t1, t2, t3, t4, t5, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C2 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var t1, t2, t3, t4, t5, C2 = function() { "use strict"; _classCallCheck(this, C2); }, D = function() { @@ -40,19 +56,23 @@ var t1, t2, t3, t4, t5, _typeof = function(obj) { _classCallCheck(this, E); }, F = function(C) { "use strict"; + _inherits(F, C); + var _super = _createSuper(F); function F() { - return _classCallCheck(this, F), _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _classCallCheck(this, F), _super.apply(this, arguments); } - return _inherits(F, C), F; + return F; }(C2), C11 = function() { "use strict"; _classCallCheck(this, C11), this.i = "foo"; }, D1 = function(C1) { "use strict"; + _inherits(D1, C1); + var _super = _createSuper(D1); function D1() { var _this; - return _classCallCheck(this, D1), _this = _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)), _this.i = "bar", _this; + return _classCallCheck(this, D1), _this = _super.apply(this, arguments), _this.i = "bar", _this; } - return _inherits(D1, C1), D1; + return D1; }(C11); t1[4], t2[4], t3[4], t4[2], t5[2]; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.1.normal/output.js index 436903ced85..757b9c016d8 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [ 1, @@ -151,21 +176,23 @@ var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); @@ -259,7 +286,7 @@ var derived2; } ] ]; // {}[] -})(Derived || (Derived = { +})(Derived1 || (Derived1 = { })); var WithContextualType; (function(WithContextualType) { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.2.minified/output.js index 8caeee4a6c4..2b9233bd7c9 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals/input.ts/es5.2.minified/output.js @@ -16,32 +16,52 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.1.normal/output.js index f24e1ef36ec..ab18babe1fd 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var List = function List() { "use strict"; _classCallCheck(this, List); @@ -51,9 +76,10 @@ var List = function List() { var DerivedList = /*#__PURE__*/ function(List) { "use strict"; _inherits(DerivedList, List); + var _super = _createSuper(DerivedList); function DerivedList() { _classCallCheck(this, DerivedList); - return _possibleConstructorReturn(this, _getPrototypeOf(DerivedList).apply(this, arguments)); + return _super.apply(this, arguments); } return DerivedList; }(List); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.2.minified/output.js index 2e33255f060..4aaae9df843 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/recursiveTypes/arrayLiteralsWithRecursiveGenerics/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var List1 = function() { _classCallCheck(this, List1); }, DerivedList = function(List) { "use strict"; - function DerivedList() { - var self, call, obj; - return _classCallCheck(this, DerivedList), self = this, call = _getPrototypeOf(DerivedList).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var List1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(DerivedList, List), DerivedList; + }(DerivedList, List); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(DerivedList); + function DerivedList() { + return _classCallCheck(this, DerivedList), _super.apply(this, arguments); + } + return DerivedList; }(List1), MyList = function() { "use strict"; _classCallCheck(this, MyList); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.1.normal/output.js index ccaf290c9b5..7b6972ab61e 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C3 = function C3() { "use strict"; _classCallCheck(this, C3); @@ -51,9 +76,10 @@ var C3 = function C3() { var D1 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D1, C3); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(C3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.2.minified/output.js index b8987764373..fcb62fcf176 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter/input.ts/es5.2.minified/output.js @@ -18,14 +18,7 @@ var E, E1, _typeof = function(obj) { _classCallCheck(this, C31); }, D1 = function(C3) { "use strict"; - function D1() { - var self, call; - return _classCallCheck(this, D1), self = this, call = _getPrototypeOf(D1).apply(this, arguments), call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -34,7 +27,35 @@ var E, E1, _typeof = function(obj) { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D1, C3), D1; + }(D1, C3); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D1); + function D1() { + return _classCallCheck(this, D1), _super.apply(this, arguments); + } + return D1; }(C31), C1 = function() { "use strict"; _classCallCheck(this, C1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.1.normal/output.js index 62e44cbc5e4..0c71cd3ce00 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C3 = function C3() { "use strict"; _classCallCheck(this, C3); @@ -51,36 +76,40 @@ var C3 = function C3() { var D1 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D1, C3); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(C3); var D2 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D2, C3); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(C3); var D3 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D3, C3); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(C3); var D4 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D4, C3); + var _super = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super.apply(this, arguments); } return D4; }(C3); @@ -90,27 +119,30 @@ var D5 = // V > U > T /*#__PURE__*/ function(C3) { "use strict"; _inherits(D5, C3); + var _super = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super.apply(this, arguments); } return D5; }(C3); var D6 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D6, C3); + var _super = _createSuper(D6); function D6() { _classCallCheck(this, D6); - return _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _super.apply(this, arguments); } return D6; }(C3); var D7 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D7, C3); + var _super = _createSuper(D7); function D7() { _classCallCheck(this, D7); - return _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _super.apply(this, arguments); } return D7; }(C3); @@ -119,27 +151,30 @@ var D8 = // test if U is a subtype of T, U, V /*#__PURE__*/ function(C3) { "use strict"; _inherits(D8, C3); + var _super = _createSuper(D8); function D8() { _classCallCheck(this, D8); - return _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _super.apply(this, arguments); } return D8; }(C3); var D9 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D9, C3); + var _super = _createSuper(D9); function D9() { _classCallCheck(this, D9); - return _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _super.apply(this, arguments); } return D9; }(C3); var D10 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D10, C3); + var _super = _createSuper(D10); function D10() { _classCallCheck(this, D10); - return _possibleConstructorReturn(this, _getPrototypeOf(D10).apply(this, arguments)); + return _super.apply(this, arguments); } return D10; }(C3); @@ -148,27 +183,30 @@ var D11 = // test if V is a subtype of T, U, V /*#__PURE__*/ function(C3) { "use strict"; _inherits(D11, C3); + var _super = _createSuper(D11); function D11() { _classCallCheck(this, D11); - return _possibleConstructorReturn(this, _getPrototypeOf(D11).apply(this, arguments)); + return _super.apply(this, arguments); } return D11; }(C3); var D12 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D12, C3); + var _super = _createSuper(D12); function D12() { _classCallCheck(this, D12); - return _possibleConstructorReturn(this, _getPrototypeOf(D12).apply(this, arguments)); + return _super.apply(this, arguments); } return D12; }(C3); var D13 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D13, C3); + var _super = _createSuper(D13); function D13() { _classCallCheck(this, D13); - return _possibleConstructorReturn(this, _getPrototypeOf(D13).apply(this, arguments)); + return _super.apply(this, arguments); } return D13; }(C3); @@ -178,36 +216,40 @@ var D14 = // Date > V > U > T /*#__PURE__*/ function(C3) { "use strict"; _inherits(D14, C3); + var _super = _createSuper(D14); function D14() { _classCallCheck(this, D14); - return _possibleConstructorReturn(this, _getPrototypeOf(D14).apply(this, arguments)); + return _super.apply(this, arguments); } return D14; }(C3); var D15 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D15, C3); + var _super = _createSuper(D15); function D15() { _classCallCheck(this, D15); - return _possibleConstructorReturn(this, _getPrototypeOf(D15).apply(this, arguments)); + return _super.apply(this, arguments); } return D15; }(C3); var D16 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D16, C3); + var _super = _createSuper(D16); function D16() { _classCallCheck(this, D16); - return _possibleConstructorReturn(this, _getPrototypeOf(D16).apply(this, arguments)); + return _super.apply(this, arguments); } return D16; }(C3); var D17 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D17, C3); + var _super = _createSuper(D17); function D17() { _classCallCheck(this, D17); - return _possibleConstructorReturn(this, _getPrototypeOf(D17).apply(this, arguments)); + return _super.apply(this, arguments); } return D17; }(C3); @@ -216,36 +258,40 @@ var D18 = // test if U is a subtype of T, U, V, Date /*#__PURE__*/ function(C3) { "use strict"; _inherits(D18, C3); + var _super = _createSuper(D18); function D18() { _classCallCheck(this, D18); - return _possibleConstructorReturn(this, _getPrototypeOf(D18).apply(this, arguments)); + return _super.apply(this, arguments); } return D18; }(C3); var D19 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D19, C3); + var _super = _createSuper(D19); function D19() { _classCallCheck(this, D19); - return _possibleConstructorReturn(this, _getPrototypeOf(D19).apply(this, arguments)); + return _super.apply(this, arguments); } return D19; }(C3); var D20 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D20, C3); + var _super = _createSuper(D20); function D20() { _classCallCheck(this, D20); - return _possibleConstructorReturn(this, _getPrototypeOf(D20).apply(this, arguments)); + return _super.apply(this, arguments); } return D20; }(C3); var D21 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D21, C3); + var _super = _createSuper(D21); function D21() { _classCallCheck(this, D21); - return _possibleConstructorReturn(this, _getPrototypeOf(D21).apply(this, arguments)); + return _super.apply(this, arguments); } return D21; }(C3); @@ -254,36 +300,40 @@ var D22 = // test if V is a subtype of T, U, V, Date /*#__PURE__*/ function(C3) { "use strict"; _inherits(D22, C3); + var _super = _createSuper(D22); function D22() { _classCallCheck(this, D22); - return _possibleConstructorReturn(this, _getPrototypeOf(D22).apply(this, arguments)); + return _super.apply(this, arguments); } return D22; }(C3); var D23 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D23, C3); + var _super = _createSuper(D23); function D23() { _classCallCheck(this, D23); - return _possibleConstructorReturn(this, _getPrototypeOf(D23).apply(this, arguments)); + return _super.apply(this, arguments); } return D23; }(C3); var D24 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D24, C3); + var _super = _createSuper(D24); function D24() { _classCallCheck(this, D24); - return _possibleConstructorReturn(this, _getPrototypeOf(D24).apply(this, arguments)); + return _super.apply(this, arguments); } return D24; }(C3); var D25 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D25, C3); + var _super = _createSuper(D25); function D25() { _classCallCheck(this, D25); - return _possibleConstructorReturn(this, _getPrototypeOf(D25).apply(this, arguments)); + return _super.apply(this, arguments); } return D25; }(C3); @@ -292,36 +342,40 @@ var D26 = // test if Date is a subtype of T, U, V, Date /*#__PURE__*/ function(C3) { "use strict"; _inherits(D26, C3); + var _super = _createSuper(D26); function D26() { _classCallCheck(this, D26); - return _possibleConstructorReturn(this, _getPrototypeOf(D26).apply(this, arguments)); + return _super.apply(this, arguments); } return D26; }(C3); var D27 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D27, C3); + var _super = _createSuper(D27); function D27() { _classCallCheck(this, D27); - return _possibleConstructorReturn(this, _getPrototypeOf(D27).apply(this, arguments)); + return _super.apply(this, arguments); } return D27; }(C3); var D28 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D28, C3); + var _super = _createSuper(D28); function D28() { _classCallCheck(this, D28); - return _possibleConstructorReturn(this, _getPrototypeOf(D28).apply(this, arguments)); + return _super.apply(this, arguments); } return D28; }(C3); var D29 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(D29, C3); + var _super = _createSuper(D29); function D29() { _classCallCheck(this, D29); - return _possibleConstructorReturn(this, _getPrototypeOf(D29).apply(this, arguments)); + return _super.apply(this, arguments); } return D29; }(C3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.2.minified/output.js index f62abf2ee2e..c74d24e42f7 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints/input.ts/es5.2.minified/output.js @@ -16,194 +16,268 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C31 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C31 = function() { "use strict"; _classCallCheck(this, C31); }, D1 = function(C3) { "use strict"; + _inherits(D1, C3); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, C3), D1; + return D1; }(C31), D2 = function(C3) { "use strict"; + _inherits(D2, C3); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, C3), D2; + return D2; }(C31), D3 = function(C3) { "use strict"; + _inherits(D3, C3); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, C3), D3; + return D3; }(C31), D4 = function(C3) { "use strict"; + _inherits(D4, C3); + var _super = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super.apply(this, arguments); } - return _inherits(D4, C3), D4; + return D4; }(C31), D5 = function(C3) { "use strict"; + _inherits(D5, C3); + var _super = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super.apply(this, arguments); } - return _inherits(D5, C3), D5; + return D5; }(C31), D6 = function(C3) { "use strict"; + _inherits(D6, C3); + var _super = _createSuper(D6); function D6() { - return _classCallCheck(this, D6), _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _classCallCheck(this, D6), _super.apply(this, arguments); } - return _inherits(D6, C3), D6; + return D6; }(C31), D7 = function(C3) { "use strict"; + _inherits(D7, C3); + var _super = _createSuper(D7); function D7() { - return _classCallCheck(this, D7), _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _classCallCheck(this, D7), _super.apply(this, arguments); } - return _inherits(D7, C3), D7; + return D7; }(C31), D8 = function(C3) { "use strict"; + _inherits(D8, C3); + var _super = _createSuper(D8); function D8() { - return _classCallCheck(this, D8), _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _classCallCheck(this, D8), _super.apply(this, arguments); } - return _inherits(D8, C3), D8; + return D8; }(C31), D9 = function(C3) { "use strict"; + _inherits(D9, C3); + var _super = _createSuper(D9); function D9() { - return _classCallCheck(this, D9), _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _classCallCheck(this, D9), _super.apply(this, arguments); } - return _inherits(D9, C3), D9; + return D9; }(C31), D10 = function(C3) { "use strict"; + _inherits(D10, C3); + var _super = _createSuper(D10); function D10() { - return _classCallCheck(this, D10), _possibleConstructorReturn(this, _getPrototypeOf(D10).apply(this, arguments)); + return _classCallCheck(this, D10), _super.apply(this, arguments); } - return _inherits(D10, C3), D10; + return D10; }(C31), D11 = function(C3) { "use strict"; + _inherits(D11, C3); + var _super = _createSuper(D11); function D11() { - return _classCallCheck(this, D11), _possibleConstructorReturn(this, _getPrototypeOf(D11).apply(this, arguments)); + return _classCallCheck(this, D11), _super.apply(this, arguments); } - return _inherits(D11, C3), D11; + return D11; }(C31), D12 = function(C3) { "use strict"; + _inherits(D12, C3); + var _super = _createSuper(D12); function D12() { - return _classCallCheck(this, D12), _possibleConstructorReturn(this, _getPrototypeOf(D12).apply(this, arguments)); + return _classCallCheck(this, D12), _super.apply(this, arguments); } - return _inherits(D12, C3), D12; + return D12; }(C31), D13 = function(C3) { "use strict"; + _inherits(D13, C3); + var _super = _createSuper(D13); function D13() { - return _classCallCheck(this, D13), _possibleConstructorReturn(this, _getPrototypeOf(D13).apply(this, arguments)); + return _classCallCheck(this, D13), _super.apply(this, arguments); } - return _inherits(D13, C3), D13; + return D13; }(C31), D14 = function(C3) { "use strict"; + _inherits(D14, C3); + var _super = _createSuper(D14); function D14() { - return _classCallCheck(this, D14), _possibleConstructorReturn(this, _getPrototypeOf(D14).apply(this, arguments)); + return _classCallCheck(this, D14), _super.apply(this, arguments); } - return _inherits(D14, C3), D14; + return D14; }(C31), D15 = function(C3) { "use strict"; + _inherits(D15, C3); + var _super = _createSuper(D15); function D15() { - return _classCallCheck(this, D15), _possibleConstructorReturn(this, _getPrototypeOf(D15).apply(this, arguments)); + return _classCallCheck(this, D15), _super.apply(this, arguments); } - return _inherits(D15, C3), D15; + return D15; }(C31), D16 = function(C3) { "use strict"; + _inherits(D16, C3); + var _super = _createSuper(D16); function D16() { - return _classCallCheck(this, D16), _possibleConstructorReturn(this, _getPrototypeOf(D16).apply(this, arguments)); + return _classCallCheck(this, D16), _super.apply(this, arguments); } - return _inherits(D16, C3), D16; + return D16; }(C31), D17 = function(C3) { "use strict"; + _inherits(D17, C3); + var _super = _createSuper(D17); function D17() { - return _classCallCheck(this, D17), _possibleConstructorReturn(this, _getPrototypeOf(D17).apply(this, arguments)); + return _classCallCheck(this, D17), _super.apply(this, arguments); } - return _inherits(D17, C3), D17; + return D17; }(C31), D18 = function(C3) { "use strict"; + _inherits(D18, C3); + var _super = _createSuper(D18); function D18() { - return _classCallCheck(this, D18), _possibleConstructorReturn(this, _getPrototypeOf(D18).apply(this, arguments)); + return _classCallCheck(this, D18), _super.apply(this, arguments); } - return _inherits(D18, C3), D18; + return D18; }(C31), D19 = function(C3) { "use strict"; + _inherits(D19, C3); + var _super = _createSuper(D19); function D19() { - return _classCallCheck(this, D19), _possibleConstructorReturn(this, _getPrototypeOf(D19).apply(this, arguments)); + return _classCallCheck(this, D19), _super.apply(this, arguments); } - return _inherits(D19, C3), D19; + return D19; }(C31), D20 = function(C3) { "use strict"; + _inherits(D20, C3); + var _super = _createSuper(D20); function D20() { - return _classCallCheck(this, D20), _possibleConstructorReturn(this, _getPrototypeOf(D20).apply(this, arguments)); + return _classCallCheck(this, D20), _super.apply(this, arguments); } - return _inherits(D20, C3), D20; + return D20; }(C31), D21 = function(C3) { "use strict"; + _inherits(D21, C3); + var _super = _createSuper(D21); function D21() { - return _classCallCheck(this, D21), _possibleConstructorReturn(this, _getPrototypeOf(D21).apply(this, arguments)); + return _classCallCheck(this, D21), _super.apply(this, arguments); } - return _inherits(D21, C3), D21; + return D21; }(C31), D22 = function(C3) { "use strict"; + _inherits(D22, C3); + var _super = _createSuper(D22); function D22() { - return _classCallCheck(this, D22), _possibleConstructorReturn(this, _getPrototypeOf(D22).apply(this, arguments)); + return _classCallCheck(this, D22), _super.apply(this, arguments); } - return _inherits(D22, C3), D22; + return D22; }(C31), D23 = function(C3) { "use strict"; + _inherits(D23, C3); + var _super = _createSuper(D23); function D23() { - return _classCallCheck(this, D23), _possibleConstructorReturn(this, _getPrototypeOf(D23).apply(this, arguments)); + return _classCallCheck(this, D23), _super.apply(this, arguments); } - return _inherits(D23, C3), D23; + return D23; }(C31), D24 = function(C3) { "use strict"; + _inherits(D24, C3); + var _super = _createSuper(D24); function D24() { - return _classCallCheck(this, D24), _possibleConstructorReturn(this, _getPrototypeOf(D24).apply(this, arguments)); + return _classCallCheck(this, D24), _super.apply(this, arguments); } - return _inherits(D24, C3), D24; + return D24; }(C31), D25 = function(C3) { "use strict"; + _inherits(D25, C3); + var _super = _createSuper(D25); function D25() { - return _classCallCheck(this, D25), _possibleConstructorReturn(this, _getPrototypeOf(D25).apply(this, arguments)); + return _classCallCheck(this, D25), _super.apply(this, arguments); } - return _inherits(D25, C3), D25; + return D25; }(C31), D26 = function(C3) { "use strict"; + _inherits(D26, C3); + var _super = _createSuper(D26); function D26() { - return _classCallCheck(this, D26), _possibleConstructorReturn(this, _getPrototypeOf(D26).apply(this, arguments)); + return _classCallCheck(this, D26), _super.apply(this, arguments); } - return _inherits(D26, C3), D26; + return D26; }(C31), D27 = function(C3) { "use strict"; + _inherits(D27, C3); + var _super = _createSuper(D27); function D27() { - return _classCallCheck(this, D27), _possibleConstructorReturn(this, _getPrototypeOf(D27).apply(this, arguments)); + return _classCallCheck(this, D27), _super.apply(this, arguments); } - return _inherits(D27, C3), D27; + return D27; }(C31), D28 = function(C3) { "use strict"; + _inherits(D28, C3); + var _super = _createSuper(D28); function D28() { - return _classCallCheck(this, D28), _possibleConstructorReturn(this, _getPrototypeOf(D28).apply(this, arguments)); + return _classCallCheck(this, D28), _super.apply(this, arguments); } - return _inherits(D28, C3), D28; + return D28; }(C31), D29 = function(C3) { "use strict"; + _inherits(D29, C3); + var _super = _createSuper(D29); function D29() { - return _classCallCheck(this, D29), _possibleConstructorReturn(this, _getPrototypeOf(D29).apply(this, arguments)); + return _classCallCheck(this, D29), _super.apply(this, arguments); } - return _inherits(D29, C3), D29; + return D29; }(C31); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.1.normal/output.js index 5af88a5b7a2..aea0d2da8ce 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -75,81 +100,90 @@ var B1 = function B1() { var D1 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D1, B1); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(B1); var D2 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D2, B1); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(B1); var D3 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D3, B1); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(B1); var D4 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D4, B1); + var _super = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super.apply(this, arguments); } return D4; }(B1); var D5 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D5, B1); + var _super = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super.apply(this, arguments); } return D5; }(B1); var D6 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D6, B1); + var _super = _createSuper(D6); function D6() { _classCallCheck(this, D6); - return _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _super.apply(this, arguments); } return D6; }(B1); var D7 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D7, B1); + var _super = _createSuper(D7); function D7() { _classCallCheck(this, D7); - return _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _super.apply(this, arguments); } return D7; }(B1); var D8 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D8, B1); + var _super = _createSuper(D8); function D8() { _classCallCheck(this, D8); - return _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _super.apply(this, arguments); } return D8; }(B1); var D9 = /*#__PURE__*/ function(B1) { "use strict"; _inherits(D9, B1); + var _super = _createSuper(D9); function D9() { _classCallCheck(this, D9); - return _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _super.apply(this, arguments); } return D9; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.2.minified/output.js index 6da51379b54..d8707451dd2 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Foo = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Foo = function() { "use strict"; _classCallCheck(this, Foo); }, B11 = function() { @@ -37,56 +53,74 @@ var _typeof = function(obj) { _classCallCheck(this, B11); }, D1 = function(B1) { "use strict"; + _inherits(D1, B1); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, B1), D1; + return D1; }(B11), D2 = function(B1) { "use strict"; + _inherits(D2, B1); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, B1), D2; + return D2; }(B11), D3 = function(B1) { "use strict"; + _inherits(D3, B1); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, B1), D3; + return D3; }(B11), D4 = function(B1) { "use strict"; + _inherits(D4, B1); + var _super = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super.apply(this, arguments); } - return _inherits(D4, B1), D4; + return D4; }(B11), D5 = function(B1) { "use strict"; + _inherits(D5, B1); + var _super = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super.apply(this, arguments); } - return _inherits(D5, B1), D5; + return D5; }(B11), D6 = function(B1) { "use strict"; + _inherits(D6, B1); + var _super = _createSuper(D6); function D6() { - return _classCallCheck(this, D6), _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _classCallCheck(this, D6), _super.apply(this, arguments); } - return _inherits(D6, B1), D6; + return D6; }(B11), D7 = function(B1) { "use strict"; + _inherits(D7, B1); + var _super = _createSuper(D7); function D7() { - return _classCallCheck(this, D7), _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _classCallCheck(this, D7), _super.apply(this, arguments); } - return _inherits(D7, B1), D7; + return D7; }(B11), D8 = function(B1) { "use strict"; + _inherits(D8, B1); + var _super = _createSuper(D8); function D8() { - return _classCallCheck(this, D8), _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _classCallCheck(this, D8), _super.apply(this, arguments); } - return _inherits(D8, B1), D8; + return D8; }(B11), D9 = function(B1) { "use strict"; + _inherits(D9, B1); + var _super = _createSuper(D9); function D9() { - return _classCallCheck(this, D9), _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _classCallCheck(this, D9), _super.apply(this, arguments); } - return _inherits(D9, B1), D9; + return D9; }(B11); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.1.normal/output.js index b27beb902d6..ba3bf412ad7 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); @@ -95,81 +120,90 @@ var M1; var D1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D1, Base); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(Base); var D2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D2, Base); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(Base); var D3 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D3, Base); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(Base); var D4 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D4, Base); + var _super = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super.apply(this, arguments); } return D4; }(Base); var D5 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D5, Base); + var _super = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super.apply(this, arguments); } return D5; }(Base); var D6 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D6, Base); + var _super = _createSuper(D6); function D6() { _classCallCheck(this, D6); - return _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _super.apply(this, arguments); } return D6; }(Base); var D7 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D7, Base); + var _super = _createSuper(D7); function D7() { _classCallCheck(this, D7); - return _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _super.apply(this, arguments); } return D7; }(Base); var D8 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D8, Base); + var _super = _createSuper(D8); function D8() { _classCallCheck(this, D8); - return _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _super.apply(this, arguments); } return D8; }(Base); var D9 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D9, Base); + var _super = _createSuper(D9); function D9() { _classCallCheck(this, D9); - return _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _super.apply(this, arguments); } return D9; }(Base); @@ -184,81 +218,90 @@ var M2; var D1 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D1, Base2); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(Base2); var D2 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D2, Base2); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(Base2); var D3 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D3, Base2); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(Base2); var D4 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D4, Base2); + var _super = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super.apply(this, arguments); } return D4; }(Base2); var D5 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D5, Base2); + var _super = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super.apply(this, arguments); } return D5; }(Base2); var D6 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D6, Base2); + var _super = _createSuper(D6); function D6() { _classCallCheck(this, D6); - return _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _super.apply(this, arguments); } return D6; }(Base2); var D7 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D7, Base2); + var _super = _createSuper(D7); function D7() { _classCallCheck(this, D7); - return _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _super.apply(this, arguments); } return D7; }(Base2); var D8 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D8, Base2); + var _super = _createSuper(D8); function D8() { _classCallCheck(this, D8); - return _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _super.apply(this, arguments); } return D8; }(Base2); var D9 = /*#__PURE__*/ function(Base2) { "use strict"; _inherits(D9, Base2); + var _super = _createSuper(D9); function D9() { _classCallCheck(this, D9); - return _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _super.apply(this, arguments); } return D9; }(Base2); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.2.minified/output.js index a03b33c5aeb..1460e6416f7 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var M1, M2, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Foo = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var M1, M2, Foo = function() { "use strict"; _classCallCheck(this, Foo); }; @@ -39,58 +55,76 @@ var M1, M2, _typeof = function(obj) { _classCallCheck(this, Base1); }, D1 = function(Base) { "use strict"; + _inherits(D1, Base); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, Base), D1; + return D1; }(Base1), D2 = function(Base) { "use strict"; + _inherits(D2, Base); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, Base), D2; + return D2; }(Base1), D3 = function(Base) { "use strict"; + _inherits(D3, Base); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, Base), D3; + return D3; }(Base1), D4 = function(Base) { "use strict"; + _inherits(D4, Base); + var _super = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super.apply(this, arguments); } - return _inherits(D4, Base), D4; + return D4; }(Base1), D5 = function(Base) { "use strict"; + _inherits(D5, Base); + var _super = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super.apply(this, arguments); } - return _inherits(D5, Base), D5; + return D5; }(Base1), D6 = function(Base) { "use strict"; + _inherits(D6, Base); + var _super = _createSuper(D6); function D6() { - return _classCallCheck(this, D6), _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _classCallCheck(this, D6), _super.apply(this, arguments); } - return _inherits(D6, Base), D6; + return D6; }(Base1), D7 = function(Base) { "use strict"; + _inherits(D7, Base); + var _super = _createSuper(D7); function D7() { - return _classCallCheck(this, D7), _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _classCallCheck(this, D7), _super.apply(this, arguments); } - return _inherits(D7, Base), D7; + return D7; }(Base1), D8 = function(Base) { "use strict"; + _inherits(D8, Base); + var _super = _createSuper(D8); function D8() { - return _classCallCheck(this, D8), _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _classCallCheck(this, D8), _super.apply(this, arguments); } - return _inherits(D8, Base), D8; + return D8; }(Base1), D9 = function(Base) { "use strict"; + _inherits(D9, Base); + var _super = _createSuper(D9); function D9() { - return _classCallCheck(this, D9), _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _classCallCheck(this, D9), _super.apply(this, arguments); } - return _inherits(D9, Base), D9; + return D9; }(Base1); }(M1 || (M1 = { })), (function(M2) { @@ -99,58 +133,76 @@ var M1, M2, _typeof = function(obj) { _classCallCheck(this, Base21); }, D1 = function(Base2) { "use strict"; + _inherits(D1, Base2); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, Base2), D1; + return D1; }(Base21), D2 = function(Base2) { "use strict"; + _inherits(D2, Base2); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, Base2), D2; + return D2; }(Base21), D3 = function(Base2) { "use strict"; + _inherits(D3, Base2); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, Base2), D3; + return D3; }(Base21), D4 = function(Base2) { "use strict"; + _inherits(D4, Base2); + var _super = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super.apply(this, arguments); } - return _inherits(D4, Base2), D4; + return D4; }(Base21), D5 = function(Base2) { "use strict"; + _inherits(D5, Base2); + var _super = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super.apply(this, arguments); } - return _inherits(D5, Base2), D5; + return D5; }(Base21), D6 = function(Base2) { "use strict"; + _inherits(D6, Base2); + var _super = _createSuper(D6); function D6() { - return _classCallCheck(this, D6), _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _classCallCheck(this, D6), _super.apply(this, arguments); } - return _inherits(D6, Base2), D6; + return D6; }(Base21), D7 = function(Base2) { "use strict"; + _inherits(D7, Base2); + var _super = _createSuper(D7); function D7() { - return _classCallCheck(this, D7), _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _classCallCheck(this, D7), _super.apply(this, arguments); } - return _inherits(D7, Base2), D7; + return D7; }(Base21), D8 = function(Base2) { "use strict"; + _inherits(D8, Base2); + var _super = _createSuper(D8); function D8() { - return _classCallCheck(this, D8), _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _classCallCheck(this, D8), _super.apply(this, arguments); } - return _inherits(D8, Base2), D8; + return D8; }(Base21), D9 = function(Base2) { "use strict"; + _inherits(D9, Base2); + var _super = _createSuper(D9); function D9() { - return _classCallCheck(this, D9), _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _classCallCheck(this, D9), _super.apply(this, arguments); } - return _inherits(D9, Base2), D9; + return D9; }(Base21); })(M2 || (M2 = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.1.normal/output.js index 75f2c70fd2b..7880d04858a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.2.minified/output.js index ce2f77fd358..00531c10307 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures2/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo1(function(x) { return [ diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.1.normal/output.js index 7f1a1dd631c..9c40ecbea4c 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // checking subtype relations for function types as it relates to contextual signature instantiation // error cases, so function calls will all result in 'any' var Errors; @@ -55,27 +80,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.2.minified/output.js index 1d4554b17eb..8ce5d768715 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures3/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors, WithGenericSignaturesInBaseType; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, WithGenericSignaturesInBaseType, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo2(function(x) { return null; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.1.normal/output.js index 0e98e6234d7..6aff57e6af6 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.2.minified/output.js index 788ad576c63..96811c1522c 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignatures4/input.ts/es5.2.minified/output.js @@ -16,40 +16,62 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo1(function(x) { return null; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.1.normal/output.js index 8eae690f446..ba2f833bcae 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.2.minified/output.js index e68e769c32f..334892428e5 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures2/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var r1arg1, r2arg1, r3arg1, r4arg1, r5arg1, r6arg1, r7arg1, r8arg1, r9arg1, r10arg1, r11arg1, r12arg1, r13arg1, r14arg1, r15arg1, r16arg1, r17arg1, r18arg1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var r1arg1, r2arg1, r3arg1, r4arg1, r5arg1, r6arg1, r7arg1, r8arg1, r9arg1, r10arg1, r11arg1, r12arg1, r13arg1, r14arg1, r15arg1, r16arg1, r17arg1, r18arg1, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo1(r1arg1), foo2(r2arg1), foo3(r3arg1), foo4(r4arg1), foo5(r5arg1), foo6(r6arg1), foo7(r7arg1), foo8(r8arg1), foo9(r9arg1), foo10(r10arg1), foo11(r11arg1), foo12(r12arg1), foo13(r13arg1), foo14(r14arg1), foo15(r15arg1), foo16(r16arg1), foo17(r17arg1), foo18(r18arg1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.1.normal/output.js index a8d0fe2e602..fca74f500ab 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // checking subtype relations for function types as it relates to contextual signature instantiation // error cases, so function calls will all result in 'any' var Errors; @@ -55,27 +80,30 @@ var Errors; var Derived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Derived); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.2.minified/output.js index a3e501ad2b9..6f46afbeade 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures3/input.ts/es5.2.minified/output.js @@ -1,3 +1,4 @@ +var Errors, WithGenericSignaturesInBaseType; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -16,42 +17,63 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Errors, WithGenericSignaturesInBaseType, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} !function(Errors) { var r1arg1, r2arg1, r3arg1, r4arg1, r5arg1, r6arg1, r7arg1, r7arg3, r8arg, r9arg, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, Derived = function(Base) { "use strict"; + _inherits(Derived, Base); + var _super = _createSuper(Derived); function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + return _classCallCheck(this, Derived), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; + return Derived2; }(Derived), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo2(r1arg1), foo7(r2arg1), foo8(r3arg1), foo10(r4arg1), foo11(r5arg1), foo12(r6arg1), foo15(r7arg1), foo15(r7arg3), foo16(r8arg), foo17(r9arg); }(Errors || (Errors = { diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.1.normal/output.js index 41956a297e1..e530562b074 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.2.minified/output.js index c94a557dedc..0edb01f5110 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures4/input.ts/es5.2.minified/output.js @@ -16,39 +16,61 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var r1arg, r2arg, r3arg, r4arg, r5arg, r6arg, r11arg, r15arg, r16arg, r17arg, r18arg, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var r1arg, r2arg, r3arg, r4arg, r5arg, r6arg, r11arg, r15arg, r16arg, r17arg, r18arg, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); foo1(r1arg), foo2(r2arg), foo3(r3arg), foo4(r4arg), foo5(r5arg), foo6(r6arg), foo11(r11arg), foo15(r15arg), foo16(r16arg), foo17(r17arg), foo18(r18arg); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures5/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.1.normal/output.js index 07ef854158a..93233d47e49 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.1.normal/output.js @@ -44,34 +44,62 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var OtherDerived = /*#__PURE__*/ function(Base) { "use strict"; _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { _classCallCheck(this, OtherDerived); - return _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _super.apply(this, arguments); } return OtherDerived; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.2.minified/output.js index 036412335d0..8b88a48431d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6/input.ts/es5.2.minified/output.js @@ -16,38 +16,60 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), OtherDerived = function(Base) { + return Derived2; +}(Derived1), OtherDerived = function(Base) { "use strict"; + _inherits(OtherDerived, Base); + var _super = _createSuper(OtherDerived); function OtherDerived() { - return _classCallCheck(this, OtherDerived), _possibleConstructorReturn(this, _getPrototypeOf(OtherDerived).apply(this, arguments)); + return _classCallCheck(this, OtherDerived), _super.apply(this, arguments); } - return _inherits(OtherDerived, Base), OtherDerived; + return OtherDerived; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.1.normal/output.js index ee6af7ec5c0..5ea14013b96 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); @@ -75,36 +102,40 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); var B4 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B4, A); + var _super = _createSuper(B4); function B4() { _classCallCheck(this, B4); - return _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _super.apply(this, arguments); } return B4; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.2.minified/output.js index f5a43f36e56..10de6783511 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A1); !function(Generics) { var A2 = function() { @@ -51,28 +71,36 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2), B4 = function(A) { "use strict"; + _inherits(B4, A); + var _super = _createSuper(B4); function B4() { - return _classCallCheck(this, B4), _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _classCallCheck(this, B4), _super.apply(this, arguments); } - return _inherits(B4, A), B4; + return B4; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.1.normal/output.js index 7e64a2f9e16..fbf965135a8 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); @@ -75,45 +102,50 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); var B4 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B4, A); + var _super = _createSuper(B4); function B4() { _classCallCheck(this, B4); - return _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _super.apply(this, arguments); } return B4; }(A); var B5 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B5, A); + var _super = _createSuper(B5); function B5() { _classCallCheck(this, B5); - return _possibleConstructorReturn(this, _getPrototypeOf(B5).apply(this, arguments)); + return _super.apply(this, arguments); } return B5; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.2.minified/output.js index fee47d18a3c..4812b25eaed 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A1); !function(Generics) { var A2 = function() { @@ -51,34 +71,44 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2), B4 = function(A) { "use strict"; + _inherits(B4, A); + var _super = _createSuper(B4); function B4() { - return _classCallCheck(this, B4), _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _classCallCheck(this, B4), _super.apply(this, arguments); } - return _inherits(B4, A), B4; + return B4; }(A2), B5 = function(A) { "use strict"; + _inherits(B5, A); + var _super = _createSuper(B5); function B5() { - return _classCallCheck(this, B5), _possibleConstructorReturn(this, _getPrototypeOf(B5).apply(this, arguments)); + return _classCallCheck(this, B5), _super.apply(this, arguments); } - return _inherits(B5, A), B5; + return B5; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.1.normal/output.js index b0a1f8c0a4d..8b6ccb09568 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,9 +76,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -66,18 +92,20 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.2.minified/output.js index 328b3707ad6..968f3f8219a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1); !function(Generics) { var A2 = function() { @@ -45,16 +63,20 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.1.normal/output.js index 2b4f4015da5..77daeac75c1 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.1.normal/output.js @@ -44,28 +44,55 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var A = function A() { "use strict"; _classCallCheck(this, A); @@ -73,9 +100,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -86,9 +114,10 @@ var A2 = function A2() { var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -99,9 +128,10 @@ var A3 = function A3() { var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); @@ -114,9 +144,10 @@ var TwoLevels; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -127,9 +158,10 @@ var TwoLevels; var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -140,9 +172,10 @@ var TwoLevels; var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.2.minified/output.js index 9cb5cc1cbfb..8ab2bc73d23 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers/input.ts/es5.2.minified/output.js @@ -16,61 +16,87 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var TwoLevels, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var TwoLevels, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived), A1 = function() { + return Derived2; +}(Derived1), A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), A21 = function() { "use strict"; _classCallCheck(this, A21); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A21), A31 = function() { "use strict"; _classCallCheck(this, A31); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A31); !function(TwoLevels) { var A4 = function() { @@ -78,28 +104,34 @@ var TwoLevels, _typeof = function(obj) { _classCallCheck(this, A4); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A4), A22 = function() { "use strict"; _classCallCheck(this, A22); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A22), A32 = function() { "use strict"; _classCallCheck(this, A32); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A32); }(TwoLevels || (TwoLevels = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.1.normal/output.js index 473ac675e8b..8d080d2a297 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var A = function A() { "use strict"; @@ -64,9 +90,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -77,9 +104,10 @@ var A2 = function A2() { var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -90,9 +118,10 @@ var A3 = function A3() { var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.2.minified/output.js index 6c6d0e34f50..72953e0fd72 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers4/input.ts/es5.2.minified/output.js @@ -16,53 +16,77 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), A21 = function() { "use strict"; _classCallCheck(this, A21); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A21), A31 = function() { "use strict"; _classCallCheck(this, A31); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A31); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.1.normal/output.js index 473ac675e8b..8d080d2a297 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var A = function A() { "use strict"; @@ -64,9 +90,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -77,9 +104,10 @@ var A2 = function A2() { var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -90,9 +118,10 @@ var A3 = function A3() { var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.2.minified/output.js index 6c6d0e34f50..72953e0fd72 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility/input.ts/es5.2.minified/output.js @@ -16,53 +16,77 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), A21 = function() { "use strict"; _classCallCheck(this, A21); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A21), A31 = function() { "use strict"; _classCallCheck(this, A31); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A31); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.1.normal/output.js index fb21e5ca77f..344f6ef6454 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var ExplicitPublic; (function(ExplicitPublic) { @@ -66,9 +92,10 @@ var ExplicitPublic; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -79,9 +106,10 @@ var ExplicitPublic; var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -92,9 +120,10 @@ var ExplicitPublic; var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); @@ -109,9 +138,10 @@ var ImplicitPublic; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -122,9 +152,10 @@ var ImplicitPublic; var B2 = /*#__PURE__*/ function(A2) { "use strict"; _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A2); @@ -135,9 +166,10 @@ var ImplicitPublic; var B3 = /*#__PURE__*/ function(A3) { "use strict"; _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.2.minified/output.js index 0e3215f5b99..2ba2e2dc8eb 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersAccessibility2/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ExplicitPublic, ImplicitPublic, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var ExplicitPublic, ImplicitPublic, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1); !function(ExplicitPublic) { var A1 = function() { @@ -45,28 +63,34 @@ var ExplicitPublic, ImplicitPublic, _typeof = function(obj) { _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), A21 = function() { "use strict"; _classCallCheck(this, A21); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A21), A31 = function() { "use strict"; _classCallCheck(this, A31); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A31); }(ExplicitPublic || (ExplicitPublic = { })), (function(ImplicitPublic) { @@ -75,28 +99,34 @@ var ExplicitPublic, ImplicitPublic, _typeof = function(obj) { _classCallCheck(this, A4); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A4), A22 = function() { "use strict"; _classCallCheck(this, A22); }, B2 = function(A2) { "use strict"; + _inherits(B2, A2); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A2), B2; + return B2; }(A22), A32 = function() { "use strict"; _classCallCheck(this, A32); }, B3 = function(A3) { "use strict"; + _inherits(B3, A3); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A3), B3; + return B3; }(A32); })(ImplicitPublic || (ImplicitPublic = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.1.normal/output.js index ee6af7ec5c0..5ea14013b96 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); @@ -75,36 +102,40 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); var B4 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B4, A); + var _super = _createSuper(B4); function B4() { _classCallCheck(this, B4); - return _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _super.apply(this, arguments); } return B4; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.2.minified/output.js index f5a43f36e56..10de6783511 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A1); !function(Generics) { var A2 = function() { @@ -51,28 +71,36 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2), B4 = function(A) { "use strict"; + _inherits(B4, A); + var _super = _createSuper(B4); function B4() { - return _classCallCheck(this, B4), _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _classCallCheck(this, B4), _super.apply(this, arguments); } - return _inherits(B4, A), B4; + return B4; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.1.normal/output.js index 7e64a2f9e16..fbf965135a8 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,18 +76,20 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); @@ -75,45 +102,50 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B2 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B2, A); + var _super = _createSuper(B2); function B2() { _classCallCheck(this, B2); - return _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _super.apply(this, arguments); } return B2; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); var B4 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B4, A); + var _super = _createSuper(B4); function B4() { _classCallCheck(this, B4); - return _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _super.apply(this, arguments); } return B4; }(A); var B5 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B5, A); + var _super = _createSuper(B5); function B5() { _classCallCheck(this, B5); - return _possibleConstructorReturn(this, _getPrototypeOf(B5).apply(this, arguments)); + return _super.apply(this, arguments); } return B5; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.2.minified/output.js index fee47d18a3c..4812b25eaed 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A1); !function(Generics) { var A2 = function() { @@ -51,34 +71,44 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B2 = function(A) { "use strict"; + _inherits(B2, A); + var _super = _createSuper(B2); function B2() { - return _classCallCheck(this, B2), _possibleConstructorReturn(this, _getPrototypeOf(B2).apply(this, arguments)); + return _classCallCheck(this, B2), _super.apply(this, arguments); } - return _inherits(B2, A), B2; + return B2; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2), B4 = function(A) { "use strict"; + _inherits(B4, A); + var _super = _createSuper(B4); function B4() { - return _classCallCheck(this, B4), _possibleConstructorReturn(this, _getPrototypeOf(B4).apply(this, arguments)); + return _classCallCheck(this, B4), _super.apply(this, arguments); } - return _inherits(B4, A), B4; + return B4; }(A2), B5 = function(A) { "use strict"; + _inherits(B5, A); + var _super = _createSuper(B5); function B5() { - return _classCallCheck(this, B5), _possibleConstructorReturn(this, _getPrototypeOf(B5).apply(this, arguments)); + return _classCallCheck(this, B5), _super.apply(this, arguments); } - return _inherits(B5, A), B5; + return B5; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.1.normal/output.js index b0a1f8c0a4d..8b6ccb09568 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -51,9 +76,10 @@ var A = function A() { var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); @@ -66,18 +92,20 @@ var Generics; var B = /*#__PURE__*/ function(A) { "use strict"; _inherits(B, A); + var _super = _createSuper(B); function B() { _classCallCheck(this, B); - return _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _super.apply(this, arguments); } return B; }(A); var B3 = /*#__PURE__*/ function(A) { "use strict"; _inherits(B3, A); + var _super = _createSuper(B3); function B3() { _classCallCheck(this, B3); - return _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _super.apply(this, arguments); } return B3; }(A); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.2.minified/output.js index 328b3707ad6..968f3f8219a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Generics, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Generics, A1 = function() { "use strict"; _classCallCheck(this, A1); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A1); !function(Generics) { var A2 = function() { @@ -45,16 +63,20 @@ var Generics, _typeof = function(obj) { _classCallCheck(this, A2); }, B = function(A) { "use strict"; + _inherits(B, A); + var _super = _createSuper(B); function B() { - return _classCallCheck(this, B), _possibleConstructorReturn(this, _getPrototypeOf(B).apply(this, arguments)); + return _classCallCheck(this, B), _super.apply(this, arguments); } - return _inherits(B, A), B; + return B; }(A2), B3 = function(A) { "use strict"; + _inherits(B3, A); + var _super = _createSuper(B3); function B3() { - return _classCallCheck(this, B3), _possibleConstructorReturn(this, _getPrototypeOf(B3).apply(this, arguments)); + return _classCallCheck(this, B3), _super.apply(this, arguments); } - return _inherits(B3, A), B3; + return B3; }(A2); }(Generics || (Generics = { })); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.1.normal/output.js index 6b6bdd4ce70..e3686782f41 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); @@ -51,135 +76,150 @@ var Base = function Base() { var D0 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D0, Base); + var _super = _createSuper(D0); function D0() { _classCallCheck(this, D0); - return _possibleConstructorReturn(this, _getPrototypeOf(D0).apply(this, arguments)); + return _super.apply(this, arguments); } return D0; }(Base); var DA = /*#__PURE__*/ function(Base) { "use strict"; _inherits(DA, Base); + var _super = _createSuper(DA); function DA() { _classCallCheck(this, DA); - return _possibleConstructorReturn(this, _getPrototypeOf(DA).apply(this, arguments)); + return _super.apply(this, arguments); } return DA; }(Base); var D1 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D1, Base); + var _super = _createSuper(D1); function D1() { _classCallCheck(this, D1); - return _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _super.apply(this, arguments); } return D1; }(Base); var D1A = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D1A, Base); + var _super = _createSuper(D1A); function D1A() { _classCallCheck(this, D1A); - return _possibleConstructorReturn(this, _getPrototypeOf(D1A).apply(this, arguments)); + return _super.apply(this, arguments); } return D1A; }(Base); var D2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D2, Base); + var _super = _createSuper(D2); function D2() { _classCallCheck(this, D2); - return _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _super.apply(this, arguments); } return D2; }(Base); var D2A = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D2A, Base); + var _super = _createSuper(D2A); function D2A() { _classCallCheck(this, D2A); - return _possibleConstructorReturn(this, _getPrototypeOf(D2A).apply(this, arguments)); + return _super.apply(this, arguments); } return D2A; }(Base); var D3 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D3, Base); + var _super = _createSuper(D3); function D3() { _classCallCheck(this, D3); - return _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _super.apply(this, arguments); } return D3; }(Base); var D3A = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D3A, Base); + var _super = _createSuper(D3A); function D3A() { _classCallCheck(this, D3A); - return _possibleConstructorReturn(this, _getPrototypeOf(D3A).apply(this, arguments)); + return _super.apply(this, arguments); } return D3A; }(Base); var D4 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D4, Base); + var _super = _createSuper(D4); function D4() { _classCallCheck(this, D4); - return _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _super.apply(this, arguments); } return D4; }(Base); var D5 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D5, Base); + var _super = _createSuper(D5); function D5() { _classCallCheck(this, D5); - return _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _super.apply(this, arguments); } return D5; }(Base); var D6 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D6, Base); + var _super = _createSuper(D6); function D6() { _classCallCheck(this, D6); - return _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _super.apply(this, arguments); } return D6; }(Base); var D7 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D7, Base); + var _super = _createSuper(D7); function D7() { _classCallCheck(this, D7); - return _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _super.apply(this, arguments); } return D7; }(Base); var D8 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D8, Base); + var _super = _createSuper(D8); function D8() { _classCallCheck(this, D8); - return _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _super.apply(this, arguments); } return D8; }(Base); var D9 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D9, Base); + var _super = _createSuper(D9); function D9() { _classCallCheck(this, D9); - return _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _super.apply(this, arguments); } return D9; }(Base); var D10 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D10, Base); + var _super = _createSuper(D10); function D10() { _classCallCheck(this, D10); - return _possibleConstructorReturn(this, _getPrototypeOf(D10).apply(this, arguments)); + return _super.apply(this, arguments); } return D10; }(Base); @@ -191,9 +231,10 @@ var E1; var D11 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D11, Base); + var _super = _createSuper(D11); function D11() { _classCallCheck(this, D11); - return _possibleConstructorReturn(this, _getPrototypeOf(D11).apply(this, arguments)); + return _super.apply(this, arguments); } return D11; }(Base); @@ -206,9 +247,10 @@ function f1() { var D12 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D12, Base); + var _super = _createSuper(D12); function D12() { _classCallCheck(this, D12); - return _possibleConstructorReturn(this, _getPrototypeOf(D12).apply(this, arguments)); + return _super.apply(this, arguments); } return D12; }(Base); @@ -223,27 +265,30 @@ var c = function c() { var D13 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D13, Base); + var _super = _createSuper(D13); function D13() { _classCallCheck(this, D13); - return _possibleConstructorReturn(this, _getPrototypeOf(D13).apply(this, arguments)); + return _super.apply(this, arguments); } return D13; }(Base); var D14 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D14, Base); + var _super = _createSuper(D14); function D14() { _classCallCheck(this, D14); - return _possibleConstructorReturn(this, _getPrototypeOf(D14).apply(this, arguments)); + return _super.apply(this, arguments); } return D14; }(Base); var D15 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D15, Base); + var _super = _createSuper(D15); function D15() { _classCallCheck(this, D15); - return _possibleConstructorReturn(this, _getPrototypeOf(D15).apply(this, arguments)); + return _super.apply(this, arguments); } return D15; }(Base); @@ -253,18 +298,20 @@ var D16 = //class D15 extends Base { /*#__PURE__*/ function(Base) { "use strict"; _inherits(D16, Base); + var _super = _createSuper(D16); function D16() { _classCallCheck(this, D16); - return _possibleConstructorReturn(this, _getPrototypeOf(D16).apply(this, arguments)); + return _super.apply(this, arguments); } return D16; }(Base); var D17 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(D17, Base); + var _super = _createSuper(D17); function D17() { _classCallCheck(this, D17); - return _possibleConstructorReturn(this, _getPrototypeOf(D17).apply(this, arguments)); + return _super.apply(this, arguments); } return D17; }(Base); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.2.minified/output.js index c667f051cf0..d2d6af842df 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything/input.ts/es5.2.minified/output.js @@ -16,121 +16,169 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var E, E1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var E, E1, Base1 = function() { "use strict"; _classCallCheck(this, Base1); }, D0 = function(Base) { "use strict"; + _inherits(D0, Base); + var _super = _createSuper(D0); function D0() { - return _classCallCheck(this, D0), _possibleConstructorReturn(this, _getPrototypeOf(D0).apply(this, arguments)); + return _classCallCheck(this, D0), _super.apply(this, arguments); } - return _inherits(D0, Base), D0; + return D0; }(Base1), DA = function(Base) { "use strict"; + _inherits(DA, Base); + var _super = _createSuper(DA); function DA() { - return _classCallCheck(this, DA), _possibleConstructorReturn(this, _getPrototypeOf(DA).apply(this, arguments)); + return _classCallCheck(this, DA), _super.apply(this, arguments); } - return _inherits(DA, Base), DA; + return DA; }(Base1), D1 = function(Base) { "use strict"; + _inherits(D1, Base); + var _super = _createSuper(D1); function D1() { - return _classCallCheck(this, D1), _possibleConstructorReturn(this, _getPrototypeOf(D1).apply(this, arguments)); + return _classCallCheck(this, D1), _super.apply(this, arguments); } - return _inherits(D1, Base), D1; + return D1; }(Base1), D1A = function(Base) { "use strict"; + _inherits(D1A, Base); + var _super = _createSuper(D1A); function D1A() { - return _classCallCheck(this, D1A), _possibleConstructorReturn(this, _getPrototypeOf(D1A).apply(this, arguments)); + return _classCallCheck(this, D1A), _super.apply(this, arguments); } - return _inherits(D1A, Base), D1A; + return D1A; }(Base1), D2 = function(Base) { "use strict"; + _inherits(D2, Base); + var _super = _createSuper(D2); function D2() { - return _classCallCheck(this, D2), _possibleConstructorReturn(this, _getPrototypeOf(D2).apply(this, arguments)); + return _classCallCheck(this, D2), _super.apply(this, arguments); } - return _inherits(D2, Base), D2; + return D2; }(Base1), D2A = function(Base) { "use strict"; + _inherits(D2A, Base); + var _super = _createSuper(D2A); function D2A() { - return _classCallCheck(this, D2A), _possibleConstructorReturn(this, _getPrototypeOf(D2A).apply(this, arguments)); + return _classCallCheck(this, D2A), _super.apply(this, arguments); } - return _inherits(D2A, Base), D2A; + return D2A; }(Base1), D3 = function(Base) { "use strict"; + _inherits(D3, Base); + var _super = _createSuper(D3); function D3() { - return _classCallCheck(this, D3), _possibleConstructorReturn(this, _getPrototypeOf(D3).apply(this, arguments)); + return _classCallCheck(this, D3), _super.apply(this, arguments); } - return _inherits(D3, Base), D3; + return D3; }(Base1), D3A = function(Base) { "use strict"; + _inherits(D3A, Base); + var _super = _createSuper(D3A); function D3A() { - return _classCallCheck(this, D3A), _possibleConstructorReturn(this, _getPrototypeOf(D3A).apply(this, arguments)); + return _classCallCheck(this, D3A), _super.apply(this, arguments); } - return _inherits(D3A, Base), D3A; + return D3A; }(Base1), D4 = function(Base) { "use strict"; + _inherits(D4, Base); + var _super = _createSuper(D4); function D4() { - return _classCallCheck(this, D4), _possibleConstructorReturn(this, _getPrototypeOf(D4).apply(this, arguments)); + return _classCallCheck(this, D4), _super.apply(this, arguments); } - return _inherits(D4, Base), D4; + return D4; }(Base1), D5 = function(Base) { "use strict"; + _inherits(D5, Base); + var _super = _createSuper(D5); function D5() { - return _classCallCheck(this, D5), _possibleConstructorReturn(this, _getPrototypeOf(D5).apply(this, arguments)); + return _classCallCheck(this, D5), _super.apply(this, arguments); } - return _inherits(D5, Base), D5; + return D5; }(Base1), D6 = function(Base) { "use strict"; + _inherits(D6, Base); + var _super = _createSuper(D6); function D6() { - return _classCallCheck(this, D6), _possibleConstructorReturn(this, _getPrototypeOf(D6).apply(this, arguments)); + return _classCallCheck(this, D6), _super.apply(this, arguments); } - return _inherits(D6, Base), D6; + return D6; }(Base1), D7 = function(Base) { "use strict"; + _inherits(D7, Base); + var _super = _createSuper(D7); function D7() { - return _classCallCheck(this, D7), _possibleConstructorReturn(this, _getPrototypeOf(D7).apply(this, arguments)); + return _classCallCheck(this, D7), _super.apply(this, arguments); } - return _inherits(D7, Base), D7; + return D7; }(Base1), D8 = function(Base) { "use strict"; + _inherits(D8, Base); + var _super = _createSuper(D8); function D8() { - return _classCallCheck(this, D8), _possibleConstructorReturn(this, _getPrototypeOf(D8).apply(this, arguments)); + return _classCallCheck(this, D8), _super.apply(this, arguments); } - return _inherits(D8, Base), D8; + return D8; }(Base1), D9 = function(Base) { "use strict"; + _inherits(D9, Base); + var _super = _createSuper(D9); function D9() { - return _classCallCheck(this, D9), _possibleConstructorReturn(this, _getPrototypeOf(D9).apply(this, arguments)); + return _classCallCheck(this, D9), _super.apply(this, arguments); } - return _inherits(D9, Base), D9; + return D9; }(Base1), D10 = function(Base) { "use strict"; + _inherits(D10, Base); + var _super = _createSuper(D10); function D10() { - return _classCallCheck(this, D10), _possibleConstructorReturn(this, _getPrototypeOf(D10).apply(this, arguments)); + return _classCallCheck(this, D10), _super.apply(this, arguments); } - return _inherits(D10, Base), D10; + return D10; }(Base1); (E1 = E || (E = { }))[E1.A = 0] = "A"; var D11 = function(Base) { "use strict"; + _inherits(D11, Base); + var _super = _createSuper(D11); function D11() { - return _classCallCheck(this, D11), _possibleConstructorReturn(this, _getPrototypeOf(D11).apply(this, arguments)); + return _classCallCheck(this, D11), _super.apply(this, arguments); } - return _inherits(D11, Base), D11; + return D11; }(Base1); function f() { } @@ -138,10 +186,12 @@ function f() { })).bar = 1; var D12 = function(Base) { "use strict"; + _inherits(D12, Base); + var _super = _createSuper(D12); function D12() { - return _classCallCheck(this, D12), _possibleConstructorReturn(this, _getPrototypeOf(D12).apply(this, arguments)); + return _classCallCheck(this, D12), _super.apply(this, arguments); } - return _inherits(D12, Base), D12; + return D12; }(Base1), c = function() { "use strict"; _classCallCheck(this, c); @@ -150,32 +200,42 @@ var D12 = function(Base) { })).bar = 1; var D13 = function(Base) { "use strict"; + _inherits(D13, Base); + var _super = _createSuper(D13); function D13() { - return _classCallCheck(this, D13), _possibleConstructorReturn(this, _getPrototypeOf(D13).apply(this, arguments)); + return _classCallCheck(this, D13), _super.apply(this, arguments); } - return _inherits(D13, Base), D13; + return D13; }(Base1), D14 = function(Base) { "use strict"; + _inherits(D14, Base); + var _super = _createSuper(D14); function D14() { - return _classCallCheck(this, D14), _possibleConstructorReturn(this, _getPrototypeOf(D14).apply(this, arguments)); + return _classCallCheck(this, D14), _super.apply(this, arguments); } - return _inherits(D14, Base), D14; + return D14; }(Base1), D15 = function(Base) { "use strict"; + _inherits(D15, Base); + var _super = _createSuper(D15); function D15() { - return _classCallCheck(this, D15), _possibleConstructorReturn(this, _getPrototypeOf(D15).apply(this, arguments)); + return _classCallCheck(this, D15), _super.apply(this, arguments); } - return _inherits(D15, Base), D15; + return D15; }(Base1), D16 = function(Base) { "use strict"; + _inherits(D16, Base); + var _super = _createSuper(D16); function D16() { - return _classCallCheck(this, D16), _possibleConstructorReturn(this, _getPrototypeOf(D16).apply(this, arguments)); + return _classCallCheck(this, D16), _super.apply(this, arguments); } - return _inherits(D16, Base), D16; + return D16; }(Base1), D17 = function(Base) { "use strict"; + _inherits(D17, Base); + var _super = _createSuper(D17); function D17() { - return _classCallCheck(this, D17), _possibleConstructorReturn(this, _getPrototypeOf(D17).apply(this, arguments)); + return _classCallCheck(this, D17), _super.apply(this, arguments); } - return _inherits(D17, Base), D17; + return D17; }(Base1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.1.normal/output.js index ef8bdaf8d81..bd19cc031b4 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -59,18 +84,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.2.minified/output.js index 2756d48a04b..dd5e83de33a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B1 = function() { @@ -40,14 +56,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.1.normal/output.js index 5fbdf27d3b9..b5e8008d8ba 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var A = function A() { "use strict"; @@ -72,18 +98,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.2.minified/output.js index a295a6670df..b38ea25eec5 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), A1 = function() { "use strict"; _classCallCheck(this, A1); @@ -49,14 +67,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.1.normal/output.js index ef8bdaf8d81..bd19cc031b4 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -59,18 +84,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.2.minified/output.js index 2756d48a04b..dd5e83de33a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B1 = function() { @@ -40,14 +56,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.1.normal/output.js index c31f21a8ebe..18ee9a7db7d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -59,18 +84,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.2.minified/output.js index 2756d48a04b..dd5e83de33a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B1 = function() { @@ -40,14 +56,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.1.normal/output.js index 0e88cb50b56..2d614123679 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -51,9 +76,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } return D; }(C); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.2.minified/output.js index 7e3ff347886..566619fbc4f 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates2/input.ts/es5.2.minified/output.js @@ -16,14 +16,7 @@ var C1 = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), D; + }(D, C); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return D; }(C1); function foo4(x) { } diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.1.normal/output.js index 18ee91b725a..47b17a2bf67 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C1 = function C1() { "use strict"; _classCallCheck(this, C1); @@ -51,9 +76,10 @@ var C1 = function C1() { var C2 = /*#__PURE__*/ function(C1) { "use strict"; _inherits(C2, C1); + var _super = _createSuper(C2); function C2() { _classCallCheck(this, C2); - return _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _super.apply(this, arguments); } return C2; }(C1); @@ -66,9 +92,10 @@ var C3 = function C3() { var C4 = /*#__PURE__*/ function(C3) { "use strict"; _inherits(C4, C3); + var _super = _createSuper(C4); function C4() { _classCallCheck(this, C4); - return _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _super.apply(this, arguments); } return C4; }(C3); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.2.minified/output.js index 905c568d0e5..1048aee9258 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3/input.ts/es5.2.minified/output.js @@ -16,35 +16,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C11 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C11 = function() { "use strict"; _classCallCheck(this, C11); }, C2 = function(C1) { "use strict"; + _inherits(C2, C1); + var _super = _createSuper(C2); function C2() { - return _classCallCheck(this, C2), _possibleConstructorReturn(this, _getPrototypeOf(C2).apply(this, arguments)); + return _classCallCheck(this, C2), _super.apply(this, arguments); } - return _inherits(C2, C1), C2; + return C2; }(C11), C31 = function() { "use strict"; _classCallCheck(this, C31); }, C4 = function(C3) { "use strict"; + _inherits(C4, C3); + var _super = _createSuper(C4); function C4() { - return _classCallCheck(this, C4), _possibleConstructorReturn(this, _getPrototypeOf(C4).apply(this, arguments)); + return _classCallCheck(this, C4), _super.apply(this, arguments); } - return _inherits(C4, C3), C4; + return C4; }(C31); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.1.normal/output.js index c31f21a8ebe..18ee9a7db7d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.1.normal/output.js @@ -44,6 +44,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var A = function A() { "use strict"; _classCallCheck(this, A); @@ -59,18 +84,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.2.minified/output.js index 2756d48a04b..dd5e83de33a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers/input.ts/es5.2.minified/output.js @@ -16,20 +16,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, A1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var A1 = function() { "use strict"; _classCallCheck(this, A1); }, B1 = function() { @@ -40,14 +56,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.1.normal/output.js index 0bd921a5f59..e507434306d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var A = function A() { "use strict"; @@ -72,18 +98,20 @@ var C = function C() { var PA = /*#__PURE__*/ function(A) { "use strict"; _inherits(PA, A); + var _super = _createSuper(PA); function PA() { _classCallCheck(this, PA); - return _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _super.apply(this, arguments); } return PA; }(A); var PB = /*#__PURE__*/ function(B) { "use strict"; _inherits(PB, B); + var _super = _createSuper(PB); function PB() { _classCallCheck(this, PB); - return _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _super.apply(this, arguments); } return PB; }(B); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.2.minified/output.js index a295a6670df..b38ea25eec5 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithStringIndexers2/input.ts/es5.2.minified/output.js @@ -16,28 +16,46 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), A1 = function() { "use strict"; _classCallCheck(this, A1); @@ -49,14 +67,18 @@ var _typeof = function(obj) { _classCallCheck(this, C); }, PA = function(A) { "use strict"; + _inherits(PA, A); + var _super = _createSuper(PA); function PA() { - return _classCallCheck(this, PA), _possibleConstructorReturn(this, _getPrototypeOf(PA).apply(this, arguments)); + return _classCallCheck(this, PA), _super.apply(this, arguments); } - return _inherits(PA, A), PA; + return PA; }(A1), PB = function(B) { "use strict"; + _inherits(PB, B); + var _super = _createSuper(PB); function PB() { - return _classCallCheck(this, PB), _possibleConstructorReturn(this, _getPrototypeOf(PB).apply(this, arguments)); + return _classCallCheck(this, PB), _super.apply(this, arguments); } - return _inherits(PB, B), PB; + return PB; }(B1); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.1.normal/output.js index 3e9ff18545b..03e7d2db82a 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.1.normal/output.js @@ -58,28 +58,55 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Derived) { "use strict"; _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; -}(Derived); +}(Derived1); var b; var d1; var d2; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.2.minified/output.js index 9e3de8fa416..5fd3106fa37 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference/input.ts/es5.2.minified/output.js @@ -22,35 +22,55 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var b, d1, d2, i1, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var b, d1, d2, i1, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Derived) { "use strict"; + _inherits(Derived2, Derived); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Derived), Derived2; -}(Derived); + return Derived2; +}(Derived1); function foo(t) { return t; } diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.1.normal/output.js index 93dff5247f6..5268c3be6da 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); @@ -74,7 +101,7 @@ function f(a) { ]; } var r = f({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }); // {}[] var r2 = f({ @@ -87,7 +114,7 @@ function f2(a) { }; } var r3 = f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }); // Derived => Derived2 var i; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.2.minified/output.js index 108439d85f9..d8939767eb0 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var i, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var i, Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); function f(a) { return [ @@ -57,12 +77,12 @@ function f2(a) { }; } f({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }), f({ x: new Base1(), y: new Derived2() }), f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }), f2(i); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.1.normal/output.js index f94a7e8cf50..aa1acd7205d 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.1.normal/output.js @@ -44,18 +44,44 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); function f(x) { var r; @@ -63,11 +89,11 @@ function f(x) { } var r1 = f({ foo: new Base(), - bar: new Derived() + bar: new Derived1() }); var r2 = f({ - foo: new Derived(), - bar: new Derived() + foo: new Derived1(), + bar: new Derived1() }); function f2(x) { var r; @@ -81,7 +107,7 @@ function f3(x, y) { var r4 = f3(new Base(), function(x) { return x; }); -var r5 = f3(new Derived(), function(x) { +var r5 = f3(new Derived1(), function(x) { return x; }); var r6 = f3(null, null); // any diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.2.minified/output.js index 942c72e235b..c8213e36b94 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2/input.ts/es5.2.minified/output.js @@ -14,16 +14,9 @@ function _setPrototypeOf(o, p) { var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - var self, call, obj; - return _classCallCheck(this, Derived), self = this, call = _getPrototypeOf(Derived).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -32,7 +25,35 @@ var Base1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(Derived, Base), Derived; + }(Derived1, Base); + var _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); + } + return Derived1; }(Base1); function f(x) { } @@ -41,13 +62,13 @@ function f3(x, y) { } f({ foo: new Base1(), - bar: new Derived() + bar: new Derived1() }), f({ - foo: new Derived(), - bar: new Derived() + foo: new Derived1(), + bar: new Derived1() }), f3(new Base1(), function(x) { return x; -}), f3(new Derived(), function(x) { +}), f3(new Derived1(), function(x) { return x; }), f3(null, null), f3(null, function(x) { return x; diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.1.normal/output.js index ad8bfd0dbd2..8ed539307cb 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.1.normal/output.js @@ -44,25 +44,52 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var Base = function Base() { "use strict"; _classCallCheck(this, Base); }; -var Derived = /*#__PURE__*/ function(Base) { +var Derived1 = /*#__PURE__*/ function(Base) { "use strict"; - _inherits(Derived, Base); - function Derived() { - _classCallCheck(this, Derived); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + _classCallCheck(this, Derived1); + return _super.apply(this, arguments); } - return Derived; + return Derived1; }(Base); var Derived2 = /*#__PURE__*/ function(Base) { "use strict"; _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { _classCallCheck(this, Derived2); - return _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _super.apply(this, arguments); } return Derived2; }(Base); @@ -71,7 +98,7 @@ function f(a) { return r; } var r1 = f({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }); // error because neither is supertype of the other function f2(a) { @@ -79,11 +106,11 @@ function f2(a) { return r; } var r2 = f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }); // ok var r3 = f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }); // ok function f3(y, x) { @@ -95,7 +122,7 @@ var r4 = f3(function(x) { }, new Base()); var r5 = f3(function(x) { return x; -}, new Derived()); +}, new Derived1()); var r6 = f3(function(x) { return x; }, null); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.2.minified/output.js index 38ed28f3e6b..7fad3888a95 100644 --- a/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3/input.ts/es5.2.minified/output.js @@ -16,34 +16,54 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, Base1 = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var Base1 = function() { "use strict"; _classCallCheck(this, Base1); -}, Derived = function(Base) { +}, Derived1 = function(Base) { "use strict"; - function Derived() { - return _classCallCheck(this, Derived), _possibleConstructorReturn(this, _getPrototypeOf(Derived).apply(this, arguments)); + _inherits(Derived1, Base); + var _super = _createSuper(Derived1); + function Derived1() { + return _classCallCheck(this, Derived1), _super.apply(this, arguments); } - return _inherits(Derived, Base), Derived; + return Derived1; }(Base1), Derived2 = function(Base) { "use strict"; + _inherits(Derived2, Base); + var _super = _createSuper(Derived2); function Derived2() { - return _classCallCheck(this, Derived2), _possibleConstructorReturn(this, _getPrototypeOf(Derived2).apply(this, arguments)); + return _classCallCheck(this, Derived2), _super.apply(this, arguments); } - return _inherits(Derived2, Base), Derived2; + return Derived2; }(Base1); function f2(a) { } @@ -51,15 +71,15 @@ function f3(y, x) { return y(null); } f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }), f2({ - x: new Derived(), + x: new Derived1(), y: new Derived2() }), f3(function(x) { return x; }, new Base1()), f3(function(x) { return x; -}, new Derived()), f3(function(x) { +}, new Derived1()), f3(function(x) { return x; }, null); diff --git a/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.1.normal/output.js index ca91b212848..965e2202ff1 100644 --- a/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} var C = function C() { "use strict"; _classCallCheck(this, C); @@ -65,9 +90,10 @@ var C = function C() { var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); + var _super = _createSuper(D); function D() { _classCallCheck(this, D); - return _possibleConstructorReturn(this, _getPrototypeOf(D).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(D, [ { diff --git a/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.2.minified/output.js index 8931f430f4e..160742b9b83 100644 --- a/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/union/unionTypeEquivalence/input.ts/es5.2.minified/output.js @@ -22,15 +22,7 @@ var C1 = function() { _classCallCheck(this, C1); }, D = function(C) { "use strict"; - var Constructor, protoProps, staticProps; - function D() { - var self, call, obj; - return _classCallCheck(this, D), self = this, call = _getPrototypeOf(D).apply(this, arguments), call && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); - } - return !function(subClass, superClass) { + !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { @@ -39,7 +31,35 @@ var C1 = function() { configurable: !0 } }), superClass && _setPrototypeOf(subClass, superClass); - }(D, C), protoProps = [ + }(D, C); + var Constructor, protoProps, staticProps, _super = function(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; + }(D); + function D() { + return _classCallCheck(this, D), _super.apply(this, arguments); + } + return protoProps = [ { key: "foo", value: function() { diff --git a/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.1.normal/output.js index c5bdac40681..f7c73f38a62 100644 --- a/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.1.normal/output.js @@ -58,6 +58,31 @@ function _setPrototypeOf(o, p) { var _typeof = function(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })); + return true; + } catch (e) { + return false; + } +} +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; +} // The resulting type an array literal expression is determined as follows: // If the array literal is empty, the resulting type is an array type with the element type Undefined. // Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name ‘0’, the resulting type is a tuple type constructed from the types of the element expressions. @@ -120,9 +145,10 @@ var D = /*#__PURE__*/ function() { var E = /*#__PURE__*/ function(C) { "use strict"; _inherits(E, C); + var _super = _createSuper(E); function E() { _classCallCheck(this, E); - return _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(E, [ { @@ -136,9 +162,10 @@ var E = /*#__PURE__*/ function(C) { var F = /*#__PURE__*/ function(C) { "use strict"; _inherits(F, C); + var _super = _createSuper(F); function F() { _classCallCheck(this, F); - return _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _super.apply(this, arguments); } _createClass(F, [ { diff --git a/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.2.minified/output.js index 926ec22508f..6b69b79f7bc 100644 --- a/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/types/union/unionTypeFromArrayLiteral/input.ts/es5.2.minified/output.js @@ -25,20 +25,36 @@ function _inherits(subClass, superClass) { } }), superClass && _setPrototypeOf(subClass, superClass); } -function _possibleConstructorReturn(self, call) { - return call && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { - if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return self; - })(self); -} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}, C = function() { +function _createSuper(Derived) { + var hasNativeReflectConstruct = function() { + if ("undefined" == typeof Reflect || !Reflect.construct) return !1; + if (Reflect.construct.sham) return !1; + if ("function" == typeof Proxy) return !0; + try { + return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { + })), !0; + } catch (e) { + return !1; + } + }(); + return function() { + var obj, self, call, result, Super = _getPrototypeOf(Derived); + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else result = Super.apply(this, arguments); + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { + if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + return self; + })(self); + }; +} +var C = function() { "use strict"; function C() { _classCallCheck(this, C); @@ -64,10 +80,12 @@ var _typeof = function(obj) { ]), D; }(), E = function(C) { "use strict"; + _inherits(E, C); + var _super = _createSuper(E); function E() { - return _classCallCheck(this, E), _possibleConstructorReturn(this, _getPrototypeOf(E).apply(this, arguments)); + return _classCallCheck(this, E), _super.apply(this, arguments); } - return _inherits(E, C), _createClass(E, [ + return _createClass(E, [ { key: "foo3", value: function() { @@ -76,10 +94,12 @@ var _typeof = function(obj) { ]), E; }(C), F = function(C) { "use strict"; + _inherits(F, C); + var _super = _createSuper(F); function F() { - return _classCallCheck(this, F), _possibleConstructorReturn(this, _getPrototypeOf(F).apply(this, arguments)); + return _classCallCheck(this, F), _super.apply(this, arguments); } - return _inherits(F, C), _createClass(F, [ + return _createClass(F, [ { key: "foo4", value: function() { diff --git a/crates/swc/tests/tsc.rs b/crates/swc/tests/tsc.rs index 8d679b579c3..9d56232cf8c 100644 --- a/crates/swc/tests/tsc.rs +++ b/crates/swc/tests/tsc.rs @@ -14,7 +14,7 @@ use swc_ecma_parser::{Syntax, TsConfig}; use testing::{NormalizedOutput, Tester}; #[testing::fixture( - "ecmascript/parser/tests/typescript/tsc/**/input.ts", + "../../ecmascript/parser/tests/typescript/tsc/**/input.ts", exclude( "privateNameFieldDestructuredBinding/input.ts", "restPropertyWithBindingPattern/input.ts", @@ -24,13 +24,15 @@ use testing::{NormalizedOutput, Tester}; "objectRestPropertyMustBeLast/input.ts", ) )] -#[testing::fixture("ecmascript/parser/tests/typescript/tsc/**/input.tsx")] +#[testing::fixture("../../ecmascript/parser/tests/typescript/tsc/**/input.tsx")] fn fixture(input: PathBuf) { if input.to_string_lossy().contains("jsdoc") { return; } - let base = Path::new("ecmascript") + let base = Path::new("..") + .join("..") + .join("ecmascript") .join("parser") .join("tests") .join("typescript") diff --git a/crates/testing_macros/src/fixture.rs b/crates/testing_macros/src/fixture.rs index 141ed174058..0edcdaf0a83 100644 --- a/crates/testing_macros/src/fixture.rs +++ b/crates/testing_macros/src/fixture.rs @@ -194,5 +194,9 @@ pub fn expand(callee: &Ident, attr: Config) -> Result, Error> { test_fns.push(f); } + if test_fns.is_empty() { + panic!("No test found") + } + Ok(test_fns) } diff --git a/ecmascript/minifier/tests/mangle.rs b/ecmascript/minifier/tests/mangle.rs index a89f8c8364d..b0968437939 100644 --- a/ecmascript/minifier/tests/mangle.rs +++ b/ecmascript/minifier/tests/mangle.rs @@ -228,7 +228,6 @@ fn fixture(input: PathBuf) { /// Tests used to prevent regressions. #[testing::fixture("tests/exec/**/input.js")] -#[testing::fixture("tests/exec/**/output.js")] fn exec(input: PathBuf) { { let s = input.to_string_lossy().replace("_", "-"); diff --git a/ecmascript/parser/tests/comments.rs b/ecmascript/parser/tests/comments.rs index 4bf32ecc199..238891983f3 100644 --- a/ecmascript/parser/tests/comments.rs +++ b/ecmascript/parser/tests/comments.rs @@ -11,8 +11,6 @@ use swc_ecma_visit::{Node, Visit, VisitWith}; use testing::{fixture, Tester}; #[fixture("tests/comments/**/input.js")] -#[fixture("tests/comments/**/input.ts")] -#[fixture("tests/comments/**/input.tsx")] fn test(input: PathBuf) { let ext = input.extension().unwrap(); let ext = ext.to_string_lossy(); diff --git a/ecmascript/parser/tests/span.rs b/ecmascript/parser/tests/span.rs index b5b55fa7be8..2b6462de02e 100644 --- a/ecmascript/parser/tests/span.rs +++ b/ecmascript/parser/tests/span.rs @@ -6,7 +6,6 @@ use swc_ecma_visit::{Node, Visit, VisitWith}; #[testing::fixture("tests/span/**/*.js")] #[testing::fixture("tests/span/**/*.ts")] -#[testing::fixture("tests/span/**/*.tsx")] fn span(entry: PathBuf) { let dir = entry.parent().unwrap().to_path_buf(); let file_name = entry