-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix content treated as string after JSX comment inside expression (#895)
* add test * fix: html comment in component inside expression * fix typo in tests * test: add more printer tests * fix jsx inline and block comments in markup * remove unused helper functions * cleanup tests * simplify comment checking logic * Fix insertion mode switch when exiting expression * chore: add __debug_bin to .gitignore * Fix code in old printer test * tidy up code * revert fix of unrelated issue * chore: changeset * chore: update lazy changeset * Update .changeset/lazy-beers-develop.md Co-authored-by: Sarah Rainsberger <[email protected]> * move `peekIs` out on `RemoveComments` * refactor `RemoveComments` to only return a string --------- Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
cef211b
commit 4f74c05
Showing
9 changed files
with
137 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/compiler': patch | ||
--- | ||
|
||
Fixes an issue where HTML and JSX comments lead to subsequent content being incorrectly treated as plain text when they have parent expressions. |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ node_modules | |
*.wasm | ||
/astro | ||
debug.test | ||
__debug_bin | ||
packages/compiler/sourcemap.mjs |
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,45 @@ | ||
package helpers | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func peekIs(input string, cur int, assert byte) bool { | ||
return cur+1 < len(input) && input[cur+1] == assert | ||
} | ||
|
||
// RemoveComments removes both block and inline comments from a string | ||
func RemoveComments(input string) string { | ||
var ( | ||
sb = strings.Builder{} | ||
inComment = false | ||
) | ||
for cur := 0; cur < len(input); cur++ { | ||
if input[cur] == '/' && !inComment { | ||
if peekIs(input, cur, '*') { | ||
inComment = true | ||
cur++ | ||
} else if peekIs(input, cur, '/') { | ||
// Skip until the end of line for inline comments | ||
for cur < len(input) && input[cur] != '\n' { | ||
cur++ | ||
} | ||
continue | ||
} | ||
} else if input[cur] == '*' && inComment && peekIs(input, cur, '/') { | ||
inComment = false | ||
cur++ | ||
continue | ||
} | ||
|
||
if !inComment { | ||
sb.WriteByte(input[cur]) | ||
} | ||
} | ||
|
||
if inComment { | ||
return "" | ||
} | ||
|
||
return strings.TrimSpace(sb.String()) | ||
} |
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
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
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