Skip to content

Commit 4e2f3a0

Browse files
authored
Merge pull request #725 from VincentMolinie/fix/null-literal-print
fix(print): fix print for NullLiteral
2 parents 64829c9 + 6bb6faa commit 4e2f3a0

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/parse-result.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,24 @@ describe('ember-template-recast', function () {
15211521
});
15221522
});
15231523

1524+
describe('NullLiteral', function () {
1525+
test('it should print correctly', function () {
1526+
let template = `{{contact-null\n null\n}}`;
1527+
1528+
let ast = parse(template);
1529+
1530+
const mustache = ast.body[0] as AST.MustacheStatement;
1531+
const param = mustache.params[0] as AST.BaseNode;
1532+
1533+
// Mark the param as dirty
1534+
const oldType = param.type;
1535+
param.type = 'ElementNode';
1536+
param.type = oldType;
1537+
1538+
expect(print(ast)).toEqual(`{{contact-null\n null\n}}`);
1539+
});
1540+
});
1541+
15241542
test('can remove during traversal by returning `null`', function () {
15251543
let template = stripIndent`
15261544
<p>here is some multiline string</p>

src/parse-result.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,11 +1109,12 @@ export default class ParseResult {
11091109
break;
11101110
case 'BooleanLiteral':
11111111
case 'NumberLiteral':
1112+
case 'NullLiteral':
11121113
{
11131114
let { source } = nodeInfo;
11141115

11151116
if (dirtyFields.has('value')) {
1116-
source = ast.value.toString();
1117+
source = ast.value?.toString() || '';
11171118
dirtyFields.delete('value');
11181119
}
11191120

0 commit comments

Comments
 (0)