Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable stage3 decorator for swc based on typescript version #5849

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/solutions/module-tools/src/builder/feature/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HookList, Context } from '../../types';
import { getProjectTsconfig } from '../../utils/dts';
import { detectTSVersion, getProjectTsconfig } from '../../utils/dts';
import { formatCjs } from './format-cjs';
import { css } from './style';
import { minify } from './terser';
Expand Down Expand Up @@ -29,6 +29,10 @@ export async function getInternalList(context: Context): Promise<HookList> {
const emitDecoratorMetadata =
userTsconfig?.compilerOptions?.emitDecoratorMetadata ?? false;

const tsVersion = await detectTSVersion(
context.api.useAppContext().appDirectory,
);

const { transformImport, transformLodash, externalHelpers, format, target } =
context.config;

Expand All @@ -42,7 +46,7 @@ export async function getInternalList(context: Context): Promise<HookList> {
: format === 'umd' || target === 'es5';
if (enbaleSwcTransform) {
const { swcTransform } = await import('./swc');
internal.push(swcTransform(userTsconfig));
internal.push(swcTransform(userTsconfig, tsVersion));
}

if (enableSwcRenderChunk) {
Expand Down
6 changes: 5 additions & 1 deletion packages/solutions/module-tools/src/builder/feature/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getSwcTarget = (target: string): JscTarget => {
return 'es2022';
};

export const swcTransform = (userTsconfig: ITsconfig) => ({
export const swcTransform = (userTsconfig: ITsconfig, tsVersion: number) => ({
yf-yang marked this conversation as resolved.
Show resolved Hide resolved
name,
apply(compiler: ICompiler) {
const tsUseDefineForClassFields =
Expand Down Expand Up @@ -102,6 +102,10 @@ export const swcTransform = (userTsconfig: ITsconfig) => ({
useDefineForClassFields,
legacyDecorator: emitDecoratorMetadata ? true : undefined,
decoratorMetadata: emitDecoratorMetadata ? true : undefined,
decoratorVersion:
!emitDecoratorMetadata && tsVersion >= 5
? '2022-03'
: undefined,
Comment on lines +105 to +108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a breaking change for projects using ts^5 and emitDecoratorMetadata not enabled?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this option takes effect only when decorator grammar is used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm fine with either. If you are willing to add another trigger option I'd like to help implement it. If you can bump to latest esbuild that'd be great 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer bumping esbuild as we should catch up the latest version and the feature is resolved by the way. We're now using 0.19.2 version of esbuild which is release 10 months ago. It's better to bump it, @chenjiahan is there any issue blocks bumping esbuild that I don't know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @chenjiahan, there's no blocking point stopping us from bumping esbuild. We'd inclined to bump esbuild to address this issue.
I'm closing this PR in favor of bumping esbuild. Let me know if you're interested in implement this. Thanks for the PR anyway.

},
externalHelpers,
target: getSwcTarget(target),
Expand Down