Skip to content

Commit b83276b

Browse files
committed
fix(cli): only preserve backticks in template literals, not comments, when blanking source
Comments start with '/' and should have all non-newline characters blanked. Only template literals (starting with backtick) need backtick preservation so tagged templates like styled`...` don't collapse into a bare name. A backtick inside a comment (e.g. a `name` reference) was surviving the blanking and could corrupt import/export specifier scanning.
1 parent 8ae6ecd commit b83276b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎packages/cli/src/commands/analyze/strong-coverage.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,17 @@ const TEXT =
156156
/**
157157
* `source` with comment and template literal text blanked, so a statement
158158
* scanner never reads code that is only text, such as a code sample in a
159-
* template string. Line breaks stay, and so do backticks, so a tagged template
160-
* never reads as a bare name. Quoted strings stay: a specifier is one, and one
161-
* ends at its line, so it cannot hold a statement.
159+
* template string. Line breaks stay; backticks stay only in template literals
160+
* so a tagged template never reads as a bare name. Quoted strings stay: a
161+
* specifier is one, and one ends at its line, so it cannot hold a statement.
162162
*
163163
* @param {string} source
164164
*/
165165
export function codeOnly(source) {
166166
return source.replace(TEXT, (text) =>
167-
text[0] === "'" || text[0] === '"' ? text : text.replace(/[^\n`]/g, ' '),
167+
text[0] === "'" || text[0] === '"'
168+
? text
169+
: text.replace(text[0] === '`' ? /[^\n`]/g : /[^\n]/g, ' '),
168170
);
169171
}
170172

0 commit comments

Comments
 (0)