diff --git a/Makefile b/Makefile index abec37615..bce89d87c 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ excludeLanguages ?= '' includePlugins ?= '' excludePlugins ?= '' singleRun ?= true +forceSwc ?= false isTest ?= false debug ?= false updateTests ?= false @@ -53,6 +54,7 @@ start dev love: --env includePlugins=$(includePlugins) \ --env excludePlugins=$(excludePlugins) \ --env isTest=$(isTest) \ + --env forceSwc=$(forceSwc) \ --env fat=$(fat) .PHONY: build diff --git a/package-lock.json b/package-lock.json index 686280aa3..09d6c1ae4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@eslint/js": "^9.16.0", "@playwright/test": "^1.49.0", "@swc/core": "^1.10.11", + "@swc/helpers": "^0.5.15", "@types/ace": "^0.0.52", "@types/fs-extra": "^11.0.4", "@types/karma": "^6.3.9", @@ -1492,6 +1493,16 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/@swc/helpers": { + "version": "0.5.15", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.15.tgz", + "integrity": "sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.8.0" + } + }, "node_modules/@swc/types": { "version": "0.1.17", "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.17.tgz", diff --git a/package.json b/package.json index 92138089e..51e776ec6 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@eslint/js": "^9.16.0", "@playwright/test": "^1.49.0", "@swc/core": "^1.10.11", + "@swc/helpers": "^0.5.15", "@types/ace": "^0.0.52", "@types/fs-extra": "^11.0.4", "@types/karma": "^6.3.9", diff --git a/src/config.ts b/src/config.ts index 0a1d731b5..d2fc8ed5b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -18,6 +18,7 @@ * @module config */ +// eslint-disable-next-line max-classes-per-file import * as consts from 'jodit/core/constants'; import { globalDocument, @@ -39,11 +40,22 @@ import type { Nullable } from './types'; +class ProtoConfig { + /** + * Behavior for buttons + */ + controls: Controls = {}; +} + +ProtoConfig.prototype.controls = {}; + /** * Default Editor's Configuration */ -class Config implements IViewOptions { - private constructor() {} +class Config extends ProtoConfig implements IViewOptions { + private constructor() { + super(); + } /** * Use cache for heavy methods @@ -940,11 +952,6 @@ class Config implements IViewOptions { } ]; - /** - * Behavior for buttons - */ - controls!: Controls; - /** * Some events are called when the editor is initialized, for example, the `afterInit` event. * So this code won't work: @@ -998,6 +1005,4 @@ class Config implements IViewOptions { } } -Config.prototype.controls = {}; - export { Config }; diff --git a/src/core/helpers/utils/assert.ts b/src/core/helpers/utils/assert.ts index a120e1dff..df9590037 100644 --- a/src/core/helpers/utils/assert.ts +++ b/src/core/helpers/utils/assert.ts @@ -4,6 +4,8 @@ * Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ +import { IS_PROD } from 'jodit/core/constants'; + /** * @module helpers/utils */ @@ -20,6 +22,10 @@ function assert( condition: T | false | 0 | '' | null | undefined, message: string ): asserts condition { + if (IS_PROD) { + return; + } + if (!condition) { throw new AssertionError(`Assertion failed: ${message}`); } diff --git a/src/jodit.ts b/src/jodit.ts index efb922610..6fd7dbdc3 100644 --- a/src/jodit.ts +++ b/src/jodit.ts @@ -1267,8 +1267,10 @@ export class Jodit extends ViewWithToolbar implements IJodit, Dlgs { }); } - currentPlace!: IWorkPlace; - places!: IWorkPlace[]; + currentPlace: IWorkPlace = { + options: this.options + } as any; + places: IWorkPlace[] = []; private readonly __elementToPlace: Map = new Map(); diff --git a/tools/rules/internal-typescript.ts b/tools/rules/internal-typescript.ts index 97b85263e..5bccc8f2f 100644 --- a/tools/rules/internal-typescript.ts +++ b/tools/rules/internal-typescript.ts @@ -20,14 +20,35 @@ export default ( isProd, isTest, fat, - superDirname + superDirname, + uglify, + forceSwc }: Variables, cwd: string ): RuleSetRule => { - return { - test: /\.(js|ts)$/, - use: [ - { + const useSWC = (isProd && !isTest && !generateTypes) || forceSwc; + if (useSWC) { + console.info('Use SWC'); + } + + const loader = useSWC + ? { + loader: 'swc-loader', + options: { + jsc: { + target: ES, + parser: { + syntax: 'typescript', + tsx: false, + dynamicImport: false, + decorators: true + } + // externalHelpers: true + }, + minify: uglify + } + } + : { loader: 'ts-loader', options: { transpileOnly: isProd && !isTest && !generateTypes, @@ -39,11 +60,16 @@ export default ( declaration: true, declarationDir: path.resolve(dirname, './build/types') }, - getCustomTransformers: (program: ts.Program) => ({ + getCustomTransformers: (): unknown => ({ before: isProd && !isTest ? [removeAsserts()] : [] }) } - }, + }; + + return { + test: /\.(js|ts)$/, + use: [ + loader, { loader: path.resolve( superDirname, diff --git a/tools/variables.ts b/tools/variables.ts index 75bdb90a3..39ccd15ec 100644 --- a/tools/variables.ts +++ b/tools/variables.ts @@ -12,6 +12,7 @@ function Bool(str: string | boolean | undefined): boolean { export type ES_TARGET = 'es5' | 'es2015' | 'es2018' | 'es2021'; export type Argv = { + forceSwc?: boolean; WEBPACK_SERVE?: boolean; filename?: (name: string) => string; env: object; @@ -33,6 +34,7 @@ export type Argv = { export type Variables = { argv: { filename?: (name: string) => string }; + forceSwc?: boolean; exclude: string[]; /** * Path to root Jodit directory @@ -119,6 +121,7 @@ export const variables = (argv: Argv, dir: string): Variables => { ? parseInt(process.env.WEBPACK_DEV_PORT) : 2000, argv, + forceSwc: Bool(argv.forceSwc), onlyTS: false, // TODO exclude, generateTypes: Bool(argv.generateTypes),