Skip to content

Commit 9e0684f

Browse files
authored
fix: scriptlets with comments (#2749)
1 parent 696cdd1 commit 9e0684f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/mean-vans-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/compiler": patch
3+
---
4+
5+
Prevent loss of comments in a scriptlet without statements

packages/compiler/src/babel-utils/parse.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ function tryParse(
134134
parserOpts.startColumn = startColumn;
135135

136136
try {
137-
return isExpression
138-
? babelParser.parseExpression(code, parserOpts)
139-
: babelParser.parse(code, parserOpts).program.body;
137+
if (isExpression) {
138+
return babelParser.parseExpression(code, parserOpts);
139+
} else {
140+
const { program } = babelParser.parse(code, parserOpts);
141+
if (program.innerComments) {
142+
return babelParser.parse(`;${code}`, parserOpts).program.body;
143+
}
144+
return program.body;
145+
}
140146
} catch (err) {
141147
const parseError = createParseError(
142148
file,

0 commit comments

Comments
 (0)