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 | 59 +++-- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 59 +++-- .../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 | 48 ++-- .../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, 26054 insertions(+), 6587 deletions(-) diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index 99f35a9fed9e..8432d3874f60 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 8084bbf35f27..3ae54fae2544 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 de0fe3e6312b..0e50c39d1027 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 78c02831a8b3..9262bcb20e22 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 d10648f12c47..cfe65155cb30 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 cd5890958396..c392977a2257 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 6c8445798a59..236d0a3d0179 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 988f98e1e900..e18074c203f4 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 74c517c2d837..be6c8ca1d833 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 8765b536e113..27a0d3de7dee 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 d10648f12c47..cfe65155cb30 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 cd5890958396..c392977a2257 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 6c8445798a59..236d0a3d0179 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 c22f8efe52a0..0bb1afc0319a 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 74c517c2d837..be6c8ca1d833 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 af3141e8fc42..896fded635b7 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 73db0654ebb5..8b6df50ef450 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 cd5890958396..c392977a2257 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 6c8445798a59..236d0a3d0179 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 5956f85bab26..9f20fd3cde90 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 69ab5df793ab..f01c26ec4e70 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 38c0a579a66e..c6fc87d36f29 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 1c553053e25f..a73a1f4ff255 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 3695d6f5d827..0943a01ce1c2 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 5d3123e1f016..a3c33b103814 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 3532250f01e7..b36a6df03298 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 6e4742f5598f..9e65aaa356e5 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 7b1634089915..b5c9b8ac91fc 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 cabaf246da65..ca182005d1cc 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 d5d1929994fa..02bf050182e9 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 27c1cd5ae9c1..f026ca8cb019 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 52171c85c0da..571735426a6e 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 958a7d49834d..641a46f4a155 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 37f0ecc3a113..1fb3da41cb1c 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 4da46b21c56f..a7911112f2ac 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 dc620c0bc848..3380142983e0 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 11c3dd558b83..5d3086f587e7 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 4db214a1fd1a..a21bad2b6b41 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 e2d55343c211..9eb16a9c5496 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 556df7c6d342..f9090c16db3c 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 1c38da5f7306..8bbe8b5e8302 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 4ad3f8292b39..81751cbf9b54 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 ad3f410746d2..f94a5d2e747e 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 f46c70f6dd9f..88cbe1bfd497 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 4a111dc34329..063a753f0bc1 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 c42a560f8211..354aa198ae0f 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 6f3f096fe0a7..d2c2e255ab42 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 07bd7f84f4fe..7ecea53ba742 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 f036d2f84b7e..d572ca18d28d 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 bfee3e20e412..8f0ba5f7b5a3 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 5d2f644f11f0..1037df8601ba 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 fecf3502029d..d20e76805028 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 996d2628d6ea..8419df55d013 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 7fcb56ab52f6..e13b064d6002 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 3d37f087bffc..8fece8bb2bb7 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 533c30b3ff33..426279c2898c 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 996d2628d6ea..8419df55d013 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 6191106ca22a..9ea65b6d7fef 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 475de8f169f7..8e9c477183e0 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 9b477bbfed70..2af430073387 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 1c9279408d05..f924e9e494b8 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 d4bc3e54485d..a3760ba6b90f 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 8caeee4a6c49..2b9233bd7c92 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 d4bc3e54485d..a3760ba6b90f 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 8caeee4a6c49..2b9233bd7c92 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 9f93778b0ed3..68c97ac8ca54 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 32661b3c0bab..bac1baf77811 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 73effe9d2cfc..f76dba77f24f 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 ffdcd0abce02..272e38ab0f8f 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 070c1b686f09..ed9038c22bed 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 5f610a7b1441..8adbbbd4bc67 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 c97e622dab96..07b59b099af6 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 836ae927e844..7b8fae4cc3dc 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 d7928b5b4eee..10d6ac4af895 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 c494fbe100cd..e8588f14e6b1 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 21b0321e11f5..ad2050f10b71 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 20ef0b75d8ca..5191d851ffd9 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 21b0321e11f5..ad2050f10b71 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 20ef0b75d8ca..5191d851ffd9 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 38c2d04fb04d..72926a964b02 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 7b3de683c0e5..dea616a84e18 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 38c2d04fb04d..72926a964b02 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 7b3de683c0e5..dea616a84e18 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 58b584e88138..43958f598b63 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 c799ce3f5db8..ef45f87b494a 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 b0f7af82f0b9..028465d507b7 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 b847ef2f5382..82c79315af24 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 c28c440a519c..015316440e2c 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 8ae720799639..c8466bf38905 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 2c80570ff6fc..b98d3d664866 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 12acd7d2e7d7..864fd947c0d3 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 603de944e577..80cfa08dc30b 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 322b948b4f3b..c4898b7456ae 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 720335da338b..749d1e9635dc 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 d24208cb0ff3..dfe16cce1551 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 a4066950dc2d..0bcd35952c55 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 5ae7cb2af89d..f5178fa7ba9b 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 256373dd50e0..b5e640e44675 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 fa43e21c3f4f..533eb791b515 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 998b71de1048..98821a2f8fef 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 db6e8a414efa..7407c9d9abb1 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 998b71de1048..98821a2f8fef 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 db6e8a414efa..7407c9d9abb1 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 c9c4cc0880ae..9df2f463abe8 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 52d167ebfe2b..98296eb9b8dd 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 d9eea855fdda..1142eefa5263 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 d6da1c5c3315..79056558e62d 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 26fadb462fcc..9c7c47958dc5 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 4fc6754111bf..752c27534be6 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 a250d3f64894..6d4fa3cea920 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 bf4d97cf9df5..883afeae8fa1 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 83121e91e425..59d32728a638 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 bf4d97cf9df5..883afeae8fa1 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 eb07094f1a1c..d6218a4015f5 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 62e660a8f3f2..0ea28395801c 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 b123d031ae4e..d1faacb771e2 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 135d86ec2839..beb0d1da447f 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 2d1da07a1da7..06da1b01c952 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 bf0c4aa003cd..937db17c9acb 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 1c52684ca8c8..5984f9a311b2 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 289bc9f80bee..fc005fcc9588 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 1fa4a8f8316b..f505e6e9e1af 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 b383ace6494a..50d69c3137b3 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 2a9f5d596301..645b08da9b2d 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 463964a86529..d52845b24c0e 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 ae1e1555d71f..262b54cb23e9 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 8907484f6cd6..a816911ad314 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 5ba5daebd240..3a1829eb65ec 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 a07801572c97..b8ad9a502165 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 7c7c4352d019..025867d9ea8e 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 297731249f88..3e366aba234e 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 72d692ce127c..9d762928ed8f 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 d395225bccb3..8389c59a7036 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 da3610174085..7675441b6499 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 974efa020134..7def54afc542 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 ab55979ef96e..0fc67af33257 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 ed0f3503843b..af758a30fa9d 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 878111a95fa2..3149be7e06bd 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 6150d6394fdf..a5a152869487 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 a77b08f5bcc2..2d16932fdd45 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 1eb3a94da37b..a9571ae18ea0 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 57b95459e076..f83782b79229 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 c4885217ff42..48945b2846cf 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 67d06887c654..637de2699963 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 9c56be59fdf7..56518d2a76d7 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 eed1ef2c05bc..574f907b0968 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 db8b9ae0e4b7..cfc534a6b62f 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 62ddd66d4f78..9b601d482fa4 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 7fc008e8353d..77680db1f122 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 3ba81ffc92e4..22a9c0450f14 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 7178777f07c3..93de082aa66f 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 38b6e08d0a54..1ba4e242f5c4 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 7178777f07c3..93de082aa66f 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 b2088aadc46a..b624bab5a4ff 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 b232f0dc6d75..a057243cd620 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 247653f8be5f..77bd10dfb3a8 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 3ae8e7d55e23..a0e48a3aef31 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 3a46194d2875..67e5d4aa046b 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 06b657ba8ef5..7089d7247c02 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 4808c13c7b66..574a96f1cc1c 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 7917c267f8e8..e2154a619ca2 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 bbd28799abef..7db4ee67d2cb 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 ef6864ae75e2..661af85a6052 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 38b6e08d0a54..1ba4e242f5c4 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 7178777f07c3..93de082aa66f 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 f0ff6dff823a..deb09d58ff93 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 df1bc8fd7b6b..0f847f9ddd15 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 cf758021fba0..92187ab69032 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 ff457f16ce62..b8edf59fe852 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 d18fc893d060..55010e67b137 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 a7bbfddba227..a18308a715ac 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 fff04f23343f..c8dad6b00a1d 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 df1bc8fd7b6b..0f847f9ddd15 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 b2f9faf16b8e..1d9b19b44aa0 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 317e6eea8283..60a21d2a0695 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 c5d4cf0ee8c5..c8760a97f7a4 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 ac1c841d7fa4..3cfab04b9620 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 4747fe1fda0d..1281f5f3d8b4 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 1414af801df8..b8b8dfb973a2 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 7a9549ee7c3f..e4f596236dfc 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 69da3ee91600..2ef7807949af 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 37fb1412d581..c753b1c8a50a 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 af39c8463955..2f44eaa70f77 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 51b7c48eb582..913b22594687 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 095e0431d3d6..51a4ccf25d81 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 7273c0de57ef..98f26c6fc38e 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 c56de23beb71..298191c8c26b 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 7273c0de57ef..98f26c6fc38e 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 c56de23beb71..298191c8c26b 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 77bcb52ed954..55f6201f1143 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 ab08c33bb1f0..992f3ea72205 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 33d0ab9808d2..4f10eeabdc8b 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 f6df71411f49..b6da3e5ace2a 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 e95022dd84d0..a9b8ae728735 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 f42c7ad957bc..a7b85ebb71ac 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 ac7e2447c640..bc8546a1afcf 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 30113b546d30..d345b0c05487 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 984b3603d37d..a88c237790fe 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 effda422289a..d5921c22bccf 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 21222587dd3b..ce61411060d6 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 1cd7c6145c15..8c7a4faef579 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 7216e3282383..896627e15583 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 2e0769ff4b3a..69ddb93bb66d 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 bc0735809cf1..245432c7f7b4 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 9c0979fd83df..3860b1d216ec 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 b0415ffa1b7f..caca4a2d060b 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 fdeb62e8071b..e2a3f98820f9 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 9098d21ea2ff..f70ff7496fc3 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 a1a2931180ca..507e90624935 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 7e27b67055de..0767196f0633 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 fbe87d9b9d9a..d1ffa1dab67b 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 18c1bff9f002..523997cffa95 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 2e0769ff4b3a..69ddb93bb66d 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 a91dc31f3dd1..e3da0ae93bb4 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 ea18d8a38b84..78e55d8545f6 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 822652c3a7c2..b36235635a31 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 c8601a4c602d..aa50e1924418 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 760b7fe9c2a7..6e573c83e7a1 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 618505502327..af89cd20f400 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 e76285e9f96a..77b93e8475d7 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 fea5eeecae25..46b758723c81 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 fb6086b86549..b668c955ec13 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 fcb530fccda5..e3191f2e1af5 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 32abf357f34b..b44d19cba9a0 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 324b4f4adfec..b26e1f505182 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 65dcb2251273..3b6cf93f9e10 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 2c453618fff9..ddc78b262ae6 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 b8542142107d..66347c4f8379 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 6337dc3998f9..83fb253ccbeb 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 638d5c1d6a06..917bb392cf5d 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 2c31642d2976..4ce19f53911a 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 43f84aced437..2288c3a31b4f 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 06c8ddb0744e..534a0e8d512c 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 bb2d3de69b40..052a0c95d5a1 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 d2824fbf22cc..445306cd1170 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 79943e25f102..48aedb08314f 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 8a7c08e4c89e..733b66ea6b67 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 ddab8d740f34..d96169b837b4 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 8b67581cbe89..56d8ea9e3ced 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 20d312f995ef..6bef6f5c481d 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 fa5855bfb5ca..1fa64e1a295f 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 e09c1eb4183f..3c5e79093405 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 fe34925f1fd8..922f2d10b808 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 6c8a6c7943e6..4d05f677eadf 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 72cb638539f8..3c6981f59cd6 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 bf594d39dc21..94e26aa08f80 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 72cb638539f8..3c6981f59cd6 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 608e0f021b9e..20cab9fa55a6 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 72cb638539f8..3c6981f59cd6 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 c9fc7cb62452..297934599a27 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 b74fb0a241b6..5f6d02f9f988 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 ef26361f16ea..863f2b726bde 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 a229f282789f..352eb2bd3127 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 458eb9b48c67..f14d2f468646 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 86228ca412c9..fec68cb1d7f2 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 9e5ed1304cc5..a4bd87312c2b 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 dea1421fce1f..2eb98c84ac52 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 5eeb15eb2788..93e27d8db636 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 67607e680e1d..c9715a444db4 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 9186915e7a83..c2f540789d79 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 61434d74f4bf..dd63e28e297b 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 bc08af2f1028..ee02255e7ae2 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 17945015aeb7..4a8c26146f6d 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 a1a4df4f2d48..058d49b18bb2 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 62c41a9a2aa3..dac0de21b528 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 ab4a338c3e0c..972421280d4b 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 43d540537b6a..02f14b5aee6c 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 f68582a81868..4a14690352ab 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 3cad8c149126..23c355964863 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 bea3b9737a11..b7367ef7aecc 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 3acfd790f863..a48f31d12f4e 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 1dc787f5937a..1e90685e3be1 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 24740e784b71..9ff12dc711ec 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 c97e622dab96..07b59b099af6 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 836ae927e844..7b8fae4cc3dc 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 2c2de73dd430..ff03530369fc 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 c494fbe100cd..e8588f14e6b1 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 76692b8213f0..72bfeae41685 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 4f2cb6572853..20fdeddcaf0b 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 1aa754932d5c..bcd883e25dc4 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 4f2cb6572853..20fdeddcaf0b 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 3efc079c9225..9dc74e30d95b 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 234920500c0d..a09c94a6f910 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 6df2289029d2..15c80e2f8dc5 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 234920500c0d..a09c94a6f910 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 0726eab786e1..8cd1de4437de 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 b3d8505322c6..1273fe26f39e 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 8c436827437f..0c64d5bae7fd 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 b3d8505322c6..1273fe26f39e 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 232f438451a8..94a6bbc4a915 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 ac26e8c03d35..2deec72f0979 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 232f438451a8..94a6bbc4a915 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 ac26e8c03d35..2deec72f0979 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 0aa1d4c159f8..6fb97ade58eb 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 d87b32bbada9..e497006ce223 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,27 +6,53 @@ 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(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: { + value: subClass, + writable: !0, + configurable: !0 + } + }), superClass && _setPrototypeOf(subClass, superClass); + }(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 = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), (function(obj, key, value) { + return _classCallCheck(this, C), _this = _super.call(this), (function(obj, key, value) { key in obj ? Object.defineProperty(obj, key, { value: value, enumerable: !0, @@ -34,17 +60,8 @@ var _typeof = function(obj) { writable: !0 }) : obj[key] = value; })({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { + }, (_this = _super.call(this), "prop"), function() { }), _this; } - 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: { - value: subClass, - writable: !0, - configurable: !0 - } - }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + 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 0aa1d4c159f8..6fb97ade58eb 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 d87b32bbada9..e497006ce223 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,27 +6,53 @@ 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(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: { + value: subClass, + writable: !0, + configurable: !0 + } + }), superClass && _setPrototypeOf(subClass, superClass); + }(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 = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), (function(obj, key, value) { + return _classCallCheck(this, C), _this = _super.call(this), (function(obj, key, value) { key in obj ? Object.defineProperty(obj, key, { value: value, enumerable: !0, @@ -34,17 +60,8 @@ var _typeof = function(obj) { writable: !0 }) : obj[key] = value; })({ - }, (_this = _possibleConstructorReturn(this, _getPrototypeOf(C).call(this)), "prop"), function() { + }, (_this = _super.call(this), "prop"), function() { }), _this; } - 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: { - value: subClass, - writable: !0, - configurable: !0 - } - }), superClass && _setPrototypeOf(subClass, superClass); - }(C, Base), C; + 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 c2994a7ee653..6b3bce36383d 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 2bebb01a5edf..be9e3c5df67e 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 c2994a7ee653..6b3bce36383d 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 2bebb01a5edf..be9e3c5df67e 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 27be4e7a9f1e..4430fe11bd99 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 c62ef7989de9..037dc2baa23a 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 9e79cc8e805a..f1c71c2d1062 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 c62ef7989de9..037dc2baa23a 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 ef220fa57e37..9d873131a524 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 6068cf925af4..0280f9593c9d 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 ef220fa57e37..9d873131a524 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 6068cf925af4..0280f9593c9d 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 d1598cbd7d2f..cf7ee152ee51 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 0f4149a7e0c3..cb16141d1360 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 d1598cbd7d2f..cf7ee152ee51 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 0f4149a7e0c3..cb16141d1360 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 d1598cbd7d2f..cf7ee152ee51 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 0f4149a7e0c3..cb16141d1360 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 d1598cbd7d2f..cf7ee152ee51 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 0f4149a7e0c3..cb16141d1360 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 8cab328ec312..ca1b61252ae3 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 2c1bedae7a84..884a6f75813e 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 f55cfb6e948e..f9ef19d8cbe0 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 05e35384f0cc..e0121e6df371 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 593cf4395c33..05bb7461df1d 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 824e90c2b101..bece2eebeb09 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 a31b314eacf2..d211655de6df 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 b69543c14215..d47d6f4a29c5 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 7a6deb5d7db8..279a74bf42a0 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 4059c1689f98..d3edc998e0fe 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 68a1edd51eb0..3a4e32a6ff51 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 c5bb3651cb0b..a695afc81c9e 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 8ab8d35500fa..9de7beab21aa 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 84ee5021b20b..cb92d3dc9ee1 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 416cd3ebc3aa..85d6c1687367 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 3d16e3c78631..043e4fab5de6 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 61eaa3f58554..fbf6dcc6549e 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 a14800f567c1..54e2e44ea7df 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 f55cfb6e948e..f9ef19d8cbe0 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 05e35384f0cc..e0121e6df371 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 ad6a4a4c812a..16b8f7388589 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 98a2045fd18c..52cf794b0ced 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 32d369b9e223..fd29f00eba19 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 8a9fd3c6230f..ffbff607efd3 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 a05f52ad3cd2..0608d33e5bd3 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 ef3ce82feff7..14e168a87965 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 fbf8e4db87ef..ad394cfea8fa 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 bf8a536bc5e5..23853f3c3a11 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 a05f52ad3cd2..0608d33e5bd3 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 ef3ce82feff7..14e168a87965 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 fbf8e4db87ef..ad394cfea8fa 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 bf8a536bc5e5..23853f3c3a11 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 a05f52ad3cd2..0608d33e5bd3 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 ef3ce82feff7..14e168a87965 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 fbf8e4db87ef..ad394cfea8fa 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 bf8a536bc5e5..23853f3c3a11 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 2c9f218a0caf..c2a72b82f347 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 b95f9b322528..5ecd4f88807a 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 0565db00c981..3331281c8a48 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 c844df4134c9..0e952c6c0bca 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 833c9d198483..75c6640e1b47 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 c844df4134c9..0e952c6c0bca 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 973567d7122d..9615736d0402 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 2cbb9bdecdc9..32ae606000d6 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 764e078c308b..f69a1d283503 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 6dfc2b48c2c8..6bf098e602b5 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 ca3ac649f786..9f57fd353862 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 84610799f175..27a1b11f6a04 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 6c158611e661..73e3552c9f6d 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 0dfee90d7dcf..5b50f22f7649 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 1874de238da0..e16e6a5b4c1d 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 4982cf6c0acc..0fb30e0e3775 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 097a7e91f158..be73638f55a6 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 5c41638b74bd..1301eec65ce3 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 2d0bebb9a981..b9bb2c9c746b 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 9d293f2b4981..f0439f9d4b47 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 6f2490340a35..ea001d54a0b9 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 1ee05fedf837..3f903659a330 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 8ab6cdabedad..2ca9cb71dbbb 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 9c61dd8dc41f..11a598e64dca 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 e9c7d16c9e38..4fd4966c1185 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 e0f9585e695a..1a4e78571887 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 20e153a571ee..6ff9a6cbf29f 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 197c99373bcd..b62b8cc5347d 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 74f258773cfb..028f49b3b31f 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 1d7053289987..2173f49717c6 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 11725bd96038..cfb514f9066d 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 d4d95713f6b5..5a717df54268 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 11725bd96038..cfb514f9066d 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 d4d95713f6b5..5a717df54268 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 f26238a5ddaa..b15674531677 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 d4d95713f6b5..5a717df54268 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 aee481e44da5..685df9d3d676 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 d4d95713f6b5..5a717df54268 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 aee481e44da5..685df9d3d676 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 d4d95713f6b5..5a717df54268 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 30879a002867..ca3dc4c994f6 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 35d40b513de6..ee500ec9b01d 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 48b157455055..08b2ba55939d 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 35d40b513de6..ee500ec9b01d 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 b495df55f201..e4848d5a81b6 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 35d40b513de6..ee500ec9b01d 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 c67c447ea9d9..effb0adc99f3 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 35d40b513de6..ee500ec9b01d 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 d84b8a10c23a..94121bd241b2 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 35d40b513de6..ee500ec9b01d 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 c1259953d430..2377db470569 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 ebeef1a86b66..d3cbc546bb98 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 017419164221..f8130cd3fa7d 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 e5a345d80db1..9f352f79ce1c 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 8d188ae97258..36cf352fd631 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 e5a345d80db1..9f352f79ce1c 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 e713c16a08e7..76d4748aa7ab 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 bc54082067ac..e0c817c082b7 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 0c2de5dca68d..c428fa1c81d3 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 763c22fee20b..ce42df9f719c 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 2ff552cb6706..1580a68cd149 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 c9a14fadc5d9..1c53beb0fa20 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 b28138246ea9..9da9464e0bca 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 382c5ee39646..2979724d8b2c 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,27 +49,49 @@ var CBase = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), CBase; }(), C = function(CBase) { "use strict"; + !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: { + value: subClass, + writable: !0, + configurable: !0 + } + }), superClass && _setPrototypeOf(subClass, superClass); + }(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 obj, self, call, _this = (self = this, (call = _getPrototypeOf(C).call(this, { + var _thisSuper, _this = _super.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, { + }); + return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(C.prototype)), "foo", _thisSuper).call(_thisSuper, { method: function(p) { p.length; } }), _this; } - 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: { - value: subClass, - writable: !0, - configurable: !0 - } - }), superClass && _setPrototypeOf(subClass, superClass); - }(C, CBase), C; + 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 a0ababbd0c8a..da226477b7b0 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 9a33d9641e5a..c029a0d29759 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 69fb79c45010..97a70123f8bb 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 24133ebc3f0e..951e51488f01 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 a6d0329e5547..2d0f8525e3c5 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 209762e25466..5d29b95530b0 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 bf95474d49d0..46a1a0ee0916 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 bc1b92c78d3e..4fe57d1ff5c7 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 b677faff051b..01f6385af50d 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 f6c2bd33c64f..b56c4eb8150c 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 f250b8bab74d..ee198b830512 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 c1f6e4220c15..ef7af1ada32f 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 a10582d07d80..6b43cb1a3228 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 e990a03f7237..0b54c3a3163c 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 951c3ac0e0e2..1d1f85907ae9 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 0c195dca1bd1..42ee4dd6284d 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 7312d0640d07..3396daf4ffde 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 5d6eee1594c1..83b2df706e48 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 816c5b0e5b2a..59f240c9f57e 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 f1587e31bfd0..e9bcb5d14324 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 a3d05be17c18..abd82230a4a0 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 de19681b6061..6fc3d7db3b4c 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 16c18802ea17..ba417952489f 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 fe49058bd757..aa5a8143525c 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 3529d8f9bb86..c351227b6271 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 f1d97a32612f..9b87815404d5 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 d73b8851b31c..0dba941fbde1 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 e2c1186e00d7..8f66250879cd 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 d2f9bef59b62..bb5a63f88bab 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 4f5e2b716b1a..529b793e13cf 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 000f75386cef..acaf3f000f52 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 c4cf2de82f71..e9285d980717 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 166366b83b8b..f546a104709d 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 d89869be3f7d..9d1d02817d96 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 bc9789e10144..8a1bbc6d11df 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 c7b8b13bec0b..a2ac5d74f1e6 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 165474a8fbd9..2276ae0068f7 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 007fb7534196..9132d54acb86 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 cda7509c715d..48b431317b36 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 a8c197449cd9..cf751afdb583 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 254449a7431b..ec13e2eb8c6c 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 949be349f2af..51eac336d385 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 d4f5c6f444c9..8c6807a81d1f 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 950483cc2762..3b3438533ace 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 59c74ac3b8bc..0e99d83fdb6e 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 64aedcb33648..d9f657495db0 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 e7d4cfca9cc0..36ff139cab5e 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 c15e573caa36..ec69e0823466 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 7d987c212994..e4219b2c5ed2 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 308439154622..0a44ee07fd03 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 df045b75f3e7..be2f0d8cd625 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 d12b63ea415f..84c49cd5fb6c 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 fc04143f4f9f..b58d033696dd 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 611c02f125a3..49b9277ea3d9 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 8eff7b25d020..0e928b64942f 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 87be12ebb36e..bc443ddb5462 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 fc03d38dde19..e4ea860017d8 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 6af21483865e..ac863e5db3a4 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 ca5eb608c09d..2a6034b25669 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 08d97ea87639..a41cc75e73ae 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 4547ab888055..87e6c4a5b861 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 a4e7ef93f978..c41e0e306bce 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 8a19c3d89ee6..d334e1336a9d 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 fa9de7b037d6..9fc12a25293e 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 68074ee52b88..260028e292d3 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 1523352c1bb7..9166b90817e3 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 6988a5eb0cd5..9d957828a836 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 9a7640a9291b..47af89ea7cc1 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 aff1dca9975b..c10cbeb547ee 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 f3902a44a32f..16d3e275f0b4 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 282ef0fc6363..9a41579ca1ab 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 b8244ceb5dea..b72da353965c 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 d24d49817d5d..8154c46b9f61 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 c15fb94e5756..01c8eddfe691 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 0aba38ea9124..94e2664104c5 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 43d31451c4a2..2f812177a85c 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 e448a38bf220..0abf4046c1ac 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 6c0385e07cbf..1e42d6a82c4c 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 ca72c803c75f..657248938efb 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 2a83d31942e5..8bda211fd48d 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 5143b8b90163..b2ba675f0386 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 661b4da9f2eb..0f64b87e4de6 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 f2d71a7d7d81..d6d26605f62c 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 661b4da9f2eb..0f64b87e4de6 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 d2d8135de2a1..8bea52346412 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 94eb5a7ebaf0..9054e4826143 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 08da45f96d90..cf4829ee7781 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 b8085c40b738..7a6f7e8e337f 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 9b4149b0145b..950711abef6d 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 57ce2d4476cf..8b4afed365fc 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 31f8c14b97b0..1a23681b5dfa 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 ba294bba495b..8e8f87610023 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 c7abd617e248..89f3b82a56c9 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 97e61f2234de..1f36956b51a6 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 89685622923c..e58f1452d7cd 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 3d3aa1f7882a..9d61ce83e334 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 7a980cf03bc1..ef2786931f19 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 ad3a2a70ec38..1b1d65db4672 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 eda2ab1ada9e..417c022fdb2b 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 7959994d9835..e592df8107cf 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 fd3848c7381e..c8054be9e40c 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 58060b5150b4..c311eb0df9b0 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 3010f05f2a03..99e8c43743de 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 baaa918169d7..d2256df97a8a 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 3010f05f2a03..99e8c43743de 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 baaa918169d7..d2256df97a8a 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 9ef9f86ac961..74ffdd39c957 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 baaa918169d7..d2256df97a8a 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 239e7c5c285c..062a38c7f4cb 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 9b544f44db5c..3459400d98bd 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 478613ea6e4d..89119e3a9e9d 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 7656afa21473..1cae254430ee 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 62c32c434bdd..86da37ccd83e 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 324235cd1231..5d4d964334e0 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 62c32c434bdd..86da37ccd83e 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 324235cd1231..5d4d964334e0 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 4000fe2fef90..b6b6174c7f25 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 e289662af2f3..f8681304d5fa 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 4c536d8968a4..acad9baea7ba 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 d708382826d5..325c5ed796ee 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 4c536d8968a4..acad9baea7ba 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 d708382826d5..325c5ed796ee 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 4c536d8968a4..acad9baea7ba 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 d708382826d5..325c5ed796ee 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 4c536d8968a4..acad9baea7ba 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 d708382826d5..325c5ed796ee 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 c54caa50e109..d6653370cd56 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 0b06632d1ff8..e162b6e1e819 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 4bf3bcf2f53e..55ee96f04143 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 c6ba635dc6a8..5c09f94324d7 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 a2e93d45b0e1..250487109b89 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 32bb1f60c54e..232babcb19ca 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 de5394a242c3..38c0e2136ba2 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 2fd339d6b57e..df088c5fc15f 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 7fc05148de8b..14290a34cd3e 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 749f5f144aeb..267383c7da3d 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 19b4d2d6e5bd..0555240dd87d 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 6f41fbdb221b..74048459cce7 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 70b0d92d6cbe..d27a6432a9e3 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 c1ce48fa9fc4..ab9f4668ef50 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 9c20046b3f82..d53d48e36f25 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 9ec33e951482..a1e2b79cc0b5 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 8255673a9868..c472c13a06db 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 74891ca4eb6f..099b451e95b5 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 8870c899cdb9..d966fc055192 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 79820970d4f2..66a240e0ebd9 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 ab4b18a54792..ae7dd403cf92 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 e0158c77f9c7..86a9d7cb3c8b 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 4f0360898340..d99958cd379c 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 225b5e4df1b2..83b936bdccc1 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 b54912600962..a4971a039581 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 8490cce5fa06..f7060a43c927 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 d2ecb1ed5391..e622a8f4bbb8 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 091b36e453f0..dc943c75d6b0 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 379f66cd5685..6ee15911a208 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 713ce7b3ba63..99d0d8c0d2d4 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 df6756202c37..36ac9ff3420d 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 abe494d3b481..ac44a10df795 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 37f4fcd4c054..6ddc6c84b7df 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 4cb6042b768f..0e473be69811 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 937117d8561e..470f5925a6cd 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 7c9e78807edc..e84ca1f9ab93 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 80aafff44cc4..36bc44b0476b 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 75ab74380111..d7d50c4e34e2 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 d237297f51df..1d623ca058f9 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 22315e66c1c0..e0259d45350c 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 6a5af975de97..e1dd4fa34739 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 22315e66c1c0..e0259d45350c 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 da411a4f8502..5c9b61a9a2cb 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 30965b3dbb83..a2d76ac3c3c7 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 b7ad93fc2d0a..271aef990578 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 8f36980973d0..4640d2344c95 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 d01a690dcf12..8bb80306fa1c 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 01abed76abae..3f8b41c9145f 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 82a3bbbd1521..ec80622a6dba 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 8d04c17f81e6..7d76c58749ae 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 c25c7f643c66..f14a42010576 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 a3f1a5ed61f6..3f2e6d48fad1 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 341e5cf735e6..94b0470ef001 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 a2c3c1479777..16de23c11266 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 085a22fee442..810118987ace 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 4c6bf93c1151..b3f2fe081396 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 afee1ac5cc46..59440acb0251 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 636ca7e24029..81cf2d8e059c 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 5ab132af2701..1a235c718c88 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 564fff59d01b..c4a12494f5f4 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 d222c11db15b..bce835828d19 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 c31ff0ee41d4..acb5df2aae82 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 159828b355d3..e4e2c3b33a6c 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 ac3c777358a7..d52adad68e2c 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 ab72d9750754..fef0b0ce7436 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 1c23b14f1784..8b3f30e1ee6b 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 5f56ee1b48b7..1ee46de0b8a5 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 45887b78ecaf..b0640f28c5f0 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 85882241948c..b1c383ca7668 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 202c6923a400..e849e4e03578 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 fc07a081fa13..76fbdc3a7948 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 202c6923a400..e849e4e03578 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 c717b1f16d3c..9ffa0a0d17e0 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 56c7adfe1c8f..bed780533d85 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 e44fe422b193..1b45718d2cf8 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 9920048e5cb2..74f0da8ca58e 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 1618c0c856f1..d824a9c85797 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 ec609aa75ab2..4ad3859c1961 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 9940736a8152..cddb3b40b55e 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 f40054166b8e..04ba9a4d46cb 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 ccf2589e56a1..82eae88f4a7b 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 99e00354f504..dc1e8234b28c 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 0bb3ab83e83c..f73559e551f4 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 7a7fc6b39c0c..3e91851b28e0 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 4ffb0952e8c5..0aa830e99a7c 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 674fab143389..35f152d892eb 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 0f6350a2b49e..9c0aa94627ca 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 8aa334ec4759..0fb9c7ee0285 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 5b3a4e46107b..c14243294aa7 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 c2f3e7c6ac53..aa87cc3b8747 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 e0688a3fbf06..c0ad186ed9e5 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 d5ca6c3873fe..c22375054ae8 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 a994fd57ecd5..58451e62926f 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 6e2f0d5ed519..7ee6b4f443aa 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 ff70c0d0ea80..ef5841e9c8d9 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 759d34c1d95e..db733310522a 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 22e80bb090c9..e3277073c77a 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 4cd80eb29d57..f4167b775f32 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 903ea1eb64c0..06fb81483a4a 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 665fae608fad..c280aab9f717 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 d0903b5bbfb0..8e58bac515c6 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 675bb653512e..6bda09a6f177 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 52c239fa69cc..a4908300f33d 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 d459ca9f6e7b..7e905eaa8a19 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 f8463913495f..7c4b6722935a 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 d0c7ef589130..373574caa15a 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 0486b8effef2..6648f3ac3520 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 b71f81cade3b..961b9722fac8 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 5ae1035ede6a..479e142a61ae 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 9b19833acd70..f1626de435aa 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 0629e2e68f5d..1eb040fa63f0 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 8e8fd9252bd5..f457e35ffdc8 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 b3a5eccf5a51..95dbc8471b99 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 02845147dfc7..c8c7e0dc6424 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 703d209a5a89..6ad1c8767efe 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 210223d0b0ed..309eb70a9cbc 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 641bdaf2395a..726e354b3484 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 d3724310d483..d461e80b7c25 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 7178777f07c3..93de082aa66f 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 48d1952c8704..fb265ac133db 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 35d40b513de6..ee500ec9b01d 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 57b7f6a5d276..e5c9ab6b3c7f 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 6f6e7532667b..7f80a1ea3f44 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 a6d71bb3df4e..511eaa67c092 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 0e1d58a80783..11982faeeadf 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 0821abf21c31..f2ab842720f3 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 792054740d08..38cddcd25901 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 a5fab82b8c71..4c17bfe91029 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 5b3cacef6cc4..d78008687afd 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 57b7f6a5d276..e5c9ab6b3c7f 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 6f6e7532667b..7f80a1ea3f44 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 b8888a8408b7..17d09b2251d6 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 0e1d58a80783..11982faeeadf 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 dff24e71bc71..9eef04a0a76c 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 792054740d08..38cddcd25901 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 a5fab82b8c71..4c17bfe91029 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 5b3cacef6cc4..d78008687afd 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 9eeb1546989b..637d80a12ad0 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 09aa14e694ff..26b03c0cb2a7 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 91fb20c85a04..79657ce38b38 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 8c02e1204ecd..49896a83ab93 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 b42841a0c928..37210f52a2a5 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 be320eddde16..94cdcec8da40 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 8e625edecd63..ee28a0379b28 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 386d14352aae..21c97558ae81 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 df6a37f81206..cd14592ee6ac 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 66ad6a1f6518..919839892ec4 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 95d7f7245beb..06920ef5b7f7 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 7fb31cc63caf..e25ebac1a957 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 dec0c7f1fd90..d98bd20fb6dd 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 902648ae3afa..77021541b9f2 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 dec0c7f1fd90..d98bd20fb6dd 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 902648ae3afa..77021541b9f2 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 80f7f2b07360..bb0c4804505f 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 62f0a40d7920..c44840a3c14e 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 8f6e2b9fb428..39049b6edf3c 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 8caeee4a6c49..2b9233bd7c92 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 7d3abc8c1365..0a44f51121dc 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 8caeee4a6c49..2b9233bd7c92 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 998a52a13cb4..3514ecc7d2c8 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 c720d35fba6e..a1b07daec653 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 436903ced857..757b9c016d8e 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 8caeee4a6c49..2b9233bd7c92 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 f24e1ef36ec1..ab18babe1fd9 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 2e33255f0609..4aaae9df843f 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 ccaf290c9b51..7b6972ab61eb 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 b89877643731..fcb62fcf1767 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 62e44cbc5e46..0c71cd3ce005 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 f62abf2ee2e1..c74d24e42f77 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 5af88a5b7a2b..aea0d2da8ce7 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 6da51379b543..d8707451dd24 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 b27beb902d6b..ba3bf412ad72 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 a03b33c5aebb..1460e6416f79 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 75f2c70fd2b1..7880d04858a6 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 ce2f77fd3586..00531c103075 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 7f1a1dd631c7..9c40ecbea4ce 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 1d4554b17eb5..8ce5d7687150 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 0e98e6234d74..6aff57e6af64 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 788ad576c63d..96811c1522c5 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 8eae690f4469..ba2f833bcae5 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 e68e769c32fb..334892428e56 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 a8d0fe2e6022..fca74f500abc 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 a3e501ad2b98..6f46afbeade7 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 41956a297e16..e530562b074f 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 c94a557dedc0..0edb01f5110f 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 07ef854158a3..93233d47e49b 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 036412335d0e..8b88a48431d1 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 ee6af7ec5c08..5ea14013b966 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 f5a43f36e560..10de67835110 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 7e64a2f9e16e..fbf965135a82 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 fee47d18a3cf..4812b25eaed7 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 b0a1f8c0a4d5..8b6ccb095684 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 328b3707ad6b..968f3f8219a7 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 2b4f4015da5d..77daeac75c11 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 9cb5cc1cbfbb..8ab2bc73d237 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 473ac675e8bd..8d080d2a297c 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 6c6d0e34f505..72953e0fd722 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 473ac675e8bd..8d080d2a297c 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 6c6d0e34f505..72953e0fd722 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 fb21e5ca77fe..344f6ef6454c 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 0e3215f5b99f..2ba2e2dc8eba 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 ee6af7ec5c08..5ea14013b966 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 f5a43f36e560..10de67835110 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 7e64a2f9e16e..fbf965135a82 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 fee47d18a3cf..4812b25eaed7 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 b0a1f8c0a4d5..8b6ccb095684 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 328b3707ad6b..968f3f8219a7 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 6b6bdd4ce706..e3686782f41c 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 c667f051cf06..d2d6af842df5 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 ef8bdaf8d816..bd19cc031b43 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 2756d48a04b8..dd5e83de33a4 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 5fbdf27d3b9a..b5e8008d8ba6 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 a295a6670df9..b38ea25eec53 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 ef8bdaf8d816..bd19cc031b43 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 2756d48a04b8..dd5e83de33a4 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 c31f21a8ebe5..18ee9a7db7d7 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 2756d48a04b8..dd5e83de33a4 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 0e88cb50b560..2d6141236799 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 7e3ff3478863..566619fbc4f5 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 18ee91b725a6..47b17a2bf675 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 905c568d0e5b..1048aee92589 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 c31f21a8ebe5..18ee9a7db7d7 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 2756d48a04b8..dd5e83de33a4 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 0bd921a5f592..e507434306d6 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 a295a6670df9..b38ea25eec53 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 3e9ff18545b2..03e7d2db82a0 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 9e3de8fa416f..5fd3106fa378 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 93dff5247f60..5268c3be6daa 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 108439d85f96..d8939767eb0d 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 f94a7e8cf503..aa1acd7205d3 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 942c72e235b4..c8213e36b946 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 ad8bfd0dbd27..8ed539307cbe 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 38ed28f3e6bf..7fad3888a958 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 ca91b212848c..965e2202ff18 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 8931f430f4eb..160742b9b83a 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 c5bdac40681e..f7c73f38a629 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 926ec22508f1..6b69b79f7bc9 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 8d679b579c3f..9d56232cf8c6 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 141ed174058a..0edcdaf0a83a 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 a89f8c8364db..b09684379393 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 4bf32ecc1991..238891983f3a 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 b5b55fa7be8e..2b6462de02eb 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