-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oxc_codegen): generate annotation comments before `CallExpressio…
…n` and `NewExpression` (#4119) 1. test case copy from `vue/core`, here are all usages of `#__PURE__` in `vue/core` https://gist.github.com/IWANABETHATGUY/c7911ecd98467a2969b2a994a34d32bc#file-pure_annotation_in_vue_repo-sh 2. Also took a look in other codebase, https://github.com/search?q=%23__PURE__&type=code, most of the usage of `#__PURE__` attached as leading comment before `CallExpression` and `NewExpression`
- Loading branch information
1 parent
44c7fe3
commit 365d9ba
Showing
4 changed files
with
72 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use oxc_ast::ast::{ArrowFunctionExpression, CallExpression, Function, NewExpression}; | ||
|
||
use crate::annotation_comment::gen_comment; | ||
use crate::{Codegen, Context}; | ||
|
||
/// the [GenComment] trait only generate annotate comments like `/* @__PURE__ */` and `/* @__NO_SIDE_EFFECTS__ */`. | ||
pub trait GenComment<const MINIFY: bool> { | ||
fn gen_comment(&self, _p: &mut Codegen<{ MINIFY }>, _ctx: Context) {} | ||
} | ||
|
||
impl<const MINIFY: bool> GenComment<MINIFY> for ArrowFunctionExpression<'_> { | ||
fn gen_comment(&self, codegen: &mut Codegen<{ MINIFY }>, _ctx: Context) { | ||
gen_comment(self.span.start, codegen); | ||
} | ||
} | ||
|
||
impl<const MINIFY: bool> GenComment<MINIFY> for Function<'_> { | ||
fn gen_comment(&self, codegen: &mut Codegen<{ MINIFY }>, _ctx: Context) { | ||
gen_comment(self.span.start, codegen); | ||
} | ||
} | ||
|
||
impl<const MINIFY: bool> GenComment<MINIFY> for CallExpression<'_> { | ||
fn gen_comment(&self, codegen: &mut Codegen<{ MINIFY }>, _ctx: Context) { | ||
gen_comment(self.span.start, codegen); | ||
} | ||
} | ||
|
||
impl<const MINIFY: bool> GenComment<MINIFY> for NewExpression<'_> { | ||
fn gen_comment(&self, codegen: &mut Codegen<{ MINIFY }>, _ctx: Context) { | ||
gen_comment(self.span.start, codegen); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters