From e04e9b69091420cd5c5cfe8234ea89d6600603ce Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Sat, 2 Dec 2023 11:38:29 +0900 Subject: [PATCH] Revert "Change target to ES5 for targeting Hermes Engine, disable noEmitHelpers, don't crash if registerOnGlobalContext fails, and disable the special transform for NativeClass decorator" This reverts commit 7e0497c8b15c96e440a9809642e0f3d441e4e871. --- packages/core/globals/index.ts | 34 ++++++++----------- packages/core/tsconfig.lib.json | 2 +- packages/core/utils/platform-check.ts | 3 +- packages/webpack5/src/configuration/base.ts | 2 +- .../src/transformers/NativeClass/index.ts | 4 +-- packages/webpack5/tsconfig.json | 2 +- tsconfig.base.json | 5 ++- 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index 3e7f2d18f..5352d79fb 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -15,27 +15,23 @@ interface ExtensionMap { } function registerOnGlobalContext(moduleName: string, exportName: string): void { - try { - Object.defineProperty(global, exportName, { - get: function () { - // We do not need to cache require() call since it is already cached in the runtime. - const m = global.loadModule(moduleName); + Object.defineProperty(global, exportName, { + get: function () { + // We do not need to cache require() call since it is already cached in the runtime. + const m = global.loadModule(moduleName); - // Redefine the property to make sure the above code is executed only once. - const resolvedValue = m[exportName]; - Object.defineProperty(global, exportName, { - value: resolvedValue, - configurable: true, - writable: true, - }); + // Redefine the property to make sure the above code is executed only once. + const resolvedValue = m[exportName]; + Object.defineProperty(global, exportName, { + value: resolvedValue, + configurable: true, + writable: true, + }); - return resolvedValue; - }, - configurable: true, - }); - } catch (_e) { - // TODO: On Hermes, some globals are non-configurable and we cannot override them. - } + return resolvedValue; + }, + configurable: true, + }); } /** diff --git a/packages/core/tsconfig.lib.json b/packages/core/tsconfig.lib.json index 9b77b8eea..8d582a2c9 100644 --- a/packages/core/tsconfig.lib.json +++ b/packages/core/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "noEmitOnError": true, - "noEmitHelpers": false, + "noEmitHelpers": true, "declaration": true, "ignoreDeprecations": "5.0", "removeComments": false, diff --git a/packages/core/utils/platform-check.ts b/packages/core/utils/platform-check.ts index 40ae84892..68f8385d9 100644 --- a/packages/core/utils/platform-check.ts +++ b/packages/core/utils/platform-check.ts @@ -2,8 +2,7 @@ * @internal Util used for exporting opposing platform utils and warning the user if they are trying to access them. */ export function platformCheck(parent?: string) { - // @ts-ignore - if (globalThis.__DEV__) { + if (__DEV__) { return new Proxy( {}, { diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 08cfdf5a1..6da829a88 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -274,7 +274,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { }, getCustomTransformers() { return { - before: [], + before: [require('../transformers/NativeClass').default], }; }, }); diff --git a/packages/webpack5/src/transformers/NativeClass/index.ts b/packages/webpack5/src/transformers/NativeClass/index.ts index f7e58b183..093304d17 100644 --- a/packages/webpack5/src/transformers/NativeClass/index.ts +++ b/packages/webpack5/src/transformers/NativeClass/index.ts @@ -5,8 +5,6 @@ import ts from 'typescript'; */ export default function (ctx: ts.TransformationContext) { function isNativeClassExtension(node: ts.ClassDeclaration) { - return false; - let decorators: Readonly; if ('canHaveDecorators' in ts && ts.canHaveDecorators(node)) { @@ -37,7 +35,7 @@ export default function (ctx: ts.TransformationContext) { node.getText().replace(/@NativeClass(\((.|\n)*?\))?/gm, ''), { compilerOptions: { - noEmitHelpers: false, + noEmitHelpers: true, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES5, experimentalDecorators: true, diff --git a/packages/webpack5/tsconfig.json b/packages/webpack5/tsconfig.json index 5a6076315..57f24b976 100644 --- a/packages/webpack5/tsconfig.json +++ b/packages/webpack5/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "rootDir": ".", "baseUrl": ".", - "target": "es5", + "target": "es2017", "module": "commonjs", "outDir": "./dist", "declaration": true, diff --git a/tsconfig.base.json b/tsconfig.base.json index d130a3e14..3a360c50d 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -2,16 +2,15 @@ "compileOnSave": false, "compilerOptions": { "rootDir": ".", - "target": "ES5", + "target": "ES2020", "module": "esnext", - "downlevelIteration": true, "sourceMap": true, "declaration": true, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "noEmitOnError": true, - "noEmitHelpers": false, + "noEmitHelpers": true, "diagnostics": true, "skipLibCheck": true, "skipDefaultLibCheck": true,