diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index ea7ac6acac235..cf977456fab5e 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -68,6 +68,7 @@ impl Gen for Hashbang<'_> { impl Gen for Directive<'_> { fn r#gen(&self, p: &mut Codegen, _ctx: Context) { + p.print_comments_at(self.span.start); p.add_source_mapping(self.span); p.print_indent(); // A Use Strict Directive may not contain an EscapeSequence or LineContinuation. diff --git a/crates/oxc_codegen/tests/integration/comments.rs b/crates/oxc_codegen/tests/integration/comments.rs index c7b44da41e0b4..60b2fd58c03c2 100644 --- a/crates/oxc_codegen/tests/integration/comments.rs +++ b/crates/oxc_codegen/tests/integration/comments.rs @@ -224,6 +224,8 @@ pub mod legal { * @preserve */ ", + // Issue #14953: legal comments above directives + "/*!\n * legal comment\n */\n\n\"use strict\";\n\nexport const foo = 'foo';", ] } diff --git a/crates/oxc_codegen/tests/integration/snapshots/legal_eof_comments.snap b/crates/oxc_codegen/tests/integration/snapshots/legal_eof_comments.snap index 577fe341271e9..9de97607ccf6a 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/legal_eof_comments.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/legal_eof_comments.snap @@ -1,5 +1,5 @@ --- -source: crates/oxc_codegen/tests/integration/main.rs +source: crates/oxc_codegen/tests/integration/tester.rs --- ########## 0 /* @license */ @@ -127,3 +127,19 @@ function foo() { /** * @preserve */ + +########## 9 +/*! + * legal comment + */ + +"use strict"; + +export const foo = 'foo'; +---------- +'use strict'; +export const foo = 'foo'; + +/*! +* legal comment +*/ diff --git a/crates/oxc_codegen/tests/integration/snapshots/legal_eof_minify_comments.snap b/crates/oxc_codegen/tests/integration/snapshots/legal_eof_minify_comments.snap index 3cd79a7c2497b..f293fabff1560 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/legal_eof_minify_comments.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/legal_eof_minify_comments.snap @@ -1,5 +1,5 @@ --- -source: crates/oxc_codegen/tests/integration/main.rs +source: crates/oxc_codegen/tests/integration/tester.rs --- ########## 0 /* @license */ @@ -109,3 +109,17 @@ function foo(){(()=>{ /** * @preserve */ + +########## 9 +/*! + * legal comment + */ + +"use strict"; + +export const foo = 'foo'; +---------- +'use strict';export const foo=`foo`; +/*! +* legal comment +*/ diff --git a/crates/oxc_codegen/tests/integration/snapshots/legal_inline_comments.snap b/crates/oxc_codegen/tests/integration/snapshots/legal_inline_comments.snap index 5b0e6df19c524..ceb457da6b039 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/legal_inline_comments.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/legal_inline_comments.snap @@ -1,5 +1,5 @@ --- -source: crates/oxc_codegen/tests/integration/main.rs +source: crates/oxc_codegen/tests/integration/tester.rs --- ########## 0 /* @license */ @@ -112,3 +112,18 @@ function foo() { /** * @preserve */ + +########## 9 +/*! + * legal comment + */ + +"use strict"; + +export const foo = 'foo'; +---------- +/*! +* legal comment +*/ +'use strict'; +export const foo = 'foo'; diff --git a/crates/oxc_codegen/tests/integration/snapshots/legal_linked_comments.snap b/crates/oxc_codegen/tests/integration/snapshots/legal_linked_comments.snap index d5f0f6b6d48d5..6b066f207559d 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/legal_linked_comments.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/legal_linked_comments.snap @@ -1,5 +1,5 @@ --- -source: crates/oxc_codegen/tests/integration/main.rs +source: crates/oxc_codegen/tests/integration/tester.rs --- ########## 0 /* @license */ @@ -108,3 +108,16 @@ function foo() { */ /*! For license information please see test.js */ +########## 9 +/*! + * legal comment + */ + +"use strict"; + +export const foo = 'foo'; +---------- +'use strict'; +export const foo = 'foo'; + +/*! For license information please see test.js */