ember-template-lint/ember-template-recast

Empty string values return invalid conversion

Closed this issue · 2 comments

One of the tests from https://github.com/ember-codemods/ember-angle-brackets-codemod/

Before ember-template-recast (correct)

input: {{foo/bar name=""}}
output: <Foo::Bar @name="" />

After ember-template-recast refactor (incorrect)

input: {{foo/bar name=""}}
output: <Foo::Bar @name= />

Mind making a failing test for this? I think something akin to

QUnit.test('adding attribute when none originally existed', function(assert) {
let template = stripIndent`
<div></div>`;
let ast = parse(template);
ast.body[0].attributes.push(builders.attr('data-test', builders.string('wheee')));
assert.equal(
print(ast),
stripIndent`
<div data-test="wheee"></div>`
);
});

    QUnit.test('adding attribute with an empty string value', function(assert) {
      let template = `<Foo></Foo>`;

      let ast = parse(template);
      ast.body[0].attributes.push(builders.attr('@name', builders.string('')));

      assert.equal(
        print(ast),
        stripIndent`
        <Foo @name=""></Foo>`
      );
    });

I'm not 100% sure what the right path forward is here. Specifically, for an ElementNode we can not easily determine the difference between <input disabled> and <input value=""> (both are represented in the AST as AttrNodes with an empty string as the value).

This is working now. Some changes were needed when moving from glimmer printer/parse/transform to ember-template-recast