Skip to content

Commit

Permalink
Merge pull request #725 from VincentMolinie/fix/null-literal-print
Browse files Browse the repository at this point in the history
fix(print): fix print for NullLiteral
  • Loading branch information
dcyriller committed Jan 14, 2022
2 parents 64829c9 + 6bb6faa commit 4e2f3a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/parse-result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,24 @@ describe('ember-template-recast', function () {
});
});

describe('NullLiteral', function () {
test('it should print correctly', function () {
let template = `{{contact-null\n null\n}}`;

let ast = parse(template);

const mustache = ast.body[0] as AST.MustacheStatement;
const param = mustache.params[0] as AST.BaseNode;

// Mark the param as dirty
const oldType = param.type;
param.type = 'ElementNode';
param.type = oldType;

expect(print(ast)).toEqual(`{{contact-null\n null\n}}`);
});
});

test('can remove during traversal by returning `null`', function () {
let template = stripIndent`
<p>here is some multiline string</p>
Expand Down
3 changes: 2 additions & 1 deletion src/parse-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,12 @@ export default class ParseResult {
break;
case 'BooleanLiteral':
case 'NumberLiteral':
case 'NullLiteral':
{
let { source } = nodeInfo;

if (dirtyFields.has('value')) {
source = ast.value.toString();
source = ast.value?.toString() || '';
dirtyFields.delete('value');
}

Expand Down

0 comments on commit 4e2f3a0

Please sign in to comment.