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(transform): support es2015 new target #1967

Merged
merged 7 commits into from
Jan 10, 2024

Conversation

underfin
Copy link
Contributor

@underfin underfin commented Jan 9, 2024

Here implementing the es2015 new target transform, see detail at https://babel.dev/docs/babel-plugin-transform-template-new-target.

Here has three kinds need to be distinguished.

  • NewTargetKind::Method, it from AstKind::ObjectMethod or AstKind::MethodDefinitionKind::Get/Set/Method. It will be transformed to void 0.
  • NewTargetKind::Constructor, is from AstKind::MethodDefinitionKind::Constructor. It will be transformed to this.constructor.
  • NewTargetKind::Function, is from AstKind::Function, here the function is not the above function. It will be transformed to this instanceof _target ? this.constructor : void 0, here _target comes from the function name or is created by scope uid ident.

@github-actions github-actions bot added A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler labels Jan 9, 2024
@Boshen Boshen requested a review from Dunqing January 9, 2024 12:37
Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

@Dunqing I think we need to add an AST nodes stack soon :-)

Copy link

codspeed-hq bot commented Jan 9, 2024

CodSpeed Performance Report

Merging #1967 will degrade performances by 5.78%

Comparing underfin:new-target (10cab35) with main (4706765)

Summary

❌ 3 regressions
✅ 11 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main underfin:new-target Change
linter[antd.js] 9.5 s 10 s -5.48%
linter[checker.ts] 4.8 s 5.1 s -5.59%
linter[pdf.mjs] 1.7 s 1.8 s -5.78%

@Boshen
Copy link
Member

Boshen commented Jan 10, 2024

There's a --exec option for updating the execution snapshot

https://github.com/oxc-project/oxc/blob/main/tasks/transform_conformance/README.md#--exec

@underfin
Copy link
Contributor Author

There's a --exec option for updating the execution snapshot

https://github.com/oxc-project/oxc/blob/main/tasks/transform_conformance/README.md#--exec

Done.

@Boshen
Copy link
Member

Boshen commented Jan 10, 2024

Waiting for @Dunqing to merge.

@Dunqing
Copy link
Member

Dunqing commented Jan 10, 2024

I will take a look this tonight 😩

@Dunqing Dunqing enabled auto-merge (squash) January 10, 2024 13:10
@Dunqing Dunqing merged commit 78b427b into oxc-project:main Jan 10, 2024
17 of 18 checks passed
@underfin underfin deleted the new-target branch January 11, 2024 06:06
IWANABETHATGUY pushed a commit to IWANABETHATGUY/oxc that referenced this pull request May 29, 2024
Here implementing the es2015 new target transform, see detail at
https://babel.dev/docs/babel-plugin-transform-template-new-target.

Here has three kinds need to be distinguished.

- `NewTargetKind::Method`, it from `AstKind::ObjectMethod` or
`AstKind::MethodDefinitionKind::Get/Set/Method`. It will be transformed
to `void 0`.
- `NewTargetKind::Constructor`, is from `
AstKind::MethodDefinitionKind::Constructor`. It will be transformed to
`this.constructor`.
- `NewTargetKind::Function`, is from ` AstKind::Function`, here the
function is not the above function. It will be transformed to `this
instanceof _target ? this.constructor : void 0`, here `_target` comes
from the function name or is created by scope uid ident.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants