[Glimmer] Preserve tilde comments (#9082)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
82603f2609
commit
90abbb7924
7 files changed
+99
-1
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Preserve tilde comments (#9082 by @kangax, @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```hbs
|
||||
{{!-- Input --}}
|
||||
{{~! Comment }}
|
||||
{{! Comment ~}}
|
||||
{{~! Comment ~}}
|
||||
|
||||
{{!-- Prettier stable --}}
|
||||
{{! Comment }}
|
||||
{{! Comment }}
|
||||
{{! Comment }}
|
||||
|
||||
{{!-- Prettier master --}}
|
||||
{{~! Comment }}
|
||||
{{! Comment ~}}
|
||||
{{~! Comment ~}}
|
||||
```
|
||||
@@ -268,8 +268,26 @@ function print(path, options, print) {
|
||||
]);
|
||||
}
|
||||
case "MustacheCommentStatement": {
|
||||
const start = locStart(n);
|
||||
const end = locEnd(n);
|
||||
// Starts with `{{~`
|
||||
const isLeftWhiteSpaceSensitive =
|
||||
options.originalText.charAt(start + 2) === "~";
|
||||
// Ends with `{{~`
|
||||
const isRightWhitespaceSensitive =
|
||||
options.originalText.charAt(end - 3) === "~";
|
||||
|
||||
const dashes = n.value.includes("}}") ? "--" : "";
|
||||
return concat(["{{!", dashes, n.value, dashes, "}}"]);
|
||||
return concat([
|
||||
"{{",
|
||||
isLeftWhiteSpaceSensitive ? "~" : "",
|
||||
"!",
|
||||
dashes,
|
||||
n.value,
|
||||
dashes,
|
||||
isRightWhitespaceSensitive ? "~" : "",
|
||||
"}}",
|
||||
]);
|
||||
}
|
||||
case "PathExpression": {
|
||||
return n.original;
|
||||
|
||||
@@ -21,9 +21,22 @@ printWidth: 80
|
||||
<div class="entry">
|
||||
{{! This comment will not be in the output }}
|
||||
{{!-- This comment as }} and will not be in the output --}}
|
||||
{{~! This comment will not be in the output }}
|
||||
{{! This comment will not be in the output ~}}
|
||||
{{~! This comment will not be in the output ~}}
|
||||
{{~!
|
||||
comment
|
||||
~}}
|
||||
{{~! 1 ~}}{{~! 2 ~}}
|
||||
<!-- This comment will be in the output -->
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{~!~}}
|
||||
<span></span>
|
||||
{{~!~}}
|
||||
</div>
|
||||
|
||||
=====================================output=====================================
|
||||
<div>
|
||||
{{! Foo }}
|
||||
@@ -40,7 +53,20 @@ printWidth: 80
|
||||
<div class="entry">
|
||||
{{! This comment will not be in the output }}
|
||||
{{!-- This comment as }} and will not be in the output --}}
|
||||
{{~! This comment will not be in the output }}
|
||||
{{! This comment will not be in the output ~}}
|
||||
{{~! This comment will not be in the output ~}}
|
||||
{{~!
|
||||
comment
|
||||
~}}
|
||||
{{~! 1 ~}}{{~! 2 ~}}
|
||||
<!-- This comment will be in the output -->
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{~!~}}
|
||||
<span></span>
|
||||
{{~!~}}
|
||||
</div>
|
||||
================================================================================
|
||||
`;
|
||||
@@ -13,5 +13,18 @@
|
||||
<div class="entry">
|
||||
{{! This comment will not be in the output }}
|
||||
{{!-- This comment as }} and will not be in the output --}}
|
||||
{{~! This comment will not be in the output }}
|
||||
{{! This comment will not be in the output ~}}
|
||||
{{~! This comment will not be in the output ~}}
|
||||
{{~!
|
||||
comment
|
||||
~}}
|
||||
{{~! 1 ~}}{{~! 2 ~}}
|
||||
<!-- This comment will be in the output -->
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{~!~}}
|
||||
<span></span>
|
||||
{{~!~}}
|
||||
</div>
|
||||
@@ -37,3 +37,23 @@ Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`tilde-comments-1.hbs [glimmer] format 1`] = `
|
||||
"Parse error on line 1:
|
||||
{{~}}
|
||||
---^
|
||||
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'CLOSE' (1:4)
|
||||
> 1 | {{~}}
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`tilde-comments-2.hbs [glimmer] format 1`] = `
|
||||
"Parse error on line 1:
|
||||
{{~~}}
|
||||
---^
|
||||
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'CLOSE' (1:4)
|
||||
> 1 | {{~~}}
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
@@ -0,0 +1 @@
|
||||
{{~}}
|
||||
@@ -0,0 +1 @@
|
||||
{{~~}}
|
||||
Reference in new issue
Block a user