Skip to content

Commit

Permalink
fix(syntax-transformer): ?? vs ? vs () 💫
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Feb 13, 2021
1 parent 311fe1e commit af12ed7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
40 changes: 32 additions & 8 deletions packages/__tests__/3-runtime-html/binding-resources.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestContext, assert } from '@aurelia/testing';
import { TestContext, assert, createFixture } from '@aurelia/testing';
import { customElement, bindable, BindingMode, Aurelia } from '@aurelia/runtime-html';

async function wait(ms: number): Promise<void> {
Expand All @@ -7,7 +7,7 @@ async function wait(ms: number): Promise<void> {

// TemplateCompiler - Binding Resources integration
describe('3-runtime-html/binding-resources.spec.ts', function () {
function createFixture() {
function $createFixture() {
const ctx = TestContext.create();
const au = new Aurelia(ctx.container);
const host = ctx.createElement('div');
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
public receiver: HTMLInputElement;
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();
au.app({ component, host });
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
public receiver: HTMLDivElement;
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();
au.app({ component, host });
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
public receiver: Receiver;
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();
au.app({ component, host });
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
public receiver: Receiver;
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();
au.app({ component, host });
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
}
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();

Expand Down Expand Up @@ -419,7 +419,7 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
public receiver: Receiver;
}

const { au, host, ctx } = createFixture();
const { au, host, ctx } = $createFixture();

const component = new App();
au.app({ component, host });
Expand Down Expand Up @@ -507,4 +507,28 @@ describe('3-runtime-html/binding-resources.spec.ts', function () {
// done();
// }, 75);
// });

it('works with updateTrigger', async function () {
const { ctx, component, startPromise, tearDown } = createFixture(
`<input ref="inputEl" value.bind="value & updateTrigger:'blur'" />`,
class App {
public value: string = '0';
public inputEl: HTMLInputElement;
}
);

await startPromise;

assert.strictEqual(component.inputEl.value, '0');

// only blur will trigger
component.inputEl.value = 'a';
component.inputEl.dispatchEvent(new ctx.CustomEvent('input'));
assert.strictEqual(component.value, '0');

component.inputEl.dispatchEvent(new ctx.CustomEvent('blur'));
assert.strictEqual(component.value, 'a');

await tearDown();
});
});
6 changes: 3 additions & 3 deletions packages/runtime-html/src/attribute-syntax-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export class AttrSyntaxTransformer {
attrSyntax.command = 'two-way';
}
const attr = attrSyntax.target;
attrSyntax.target = this.tagAttrMap[node.tagName]?.[attr]
attrSyntax.target = this.tagAttrMap[node.tagName]?.[attr] as string
?? this.globalAttrMap[attr]
?? isDataAttribute(node, attr, this.svg)
?? (isDataAttribute(node, attr, this.svg)
? attr
: camelCase(attr);
: camelCase(attr));
// attrSyntax.target = this.map(node.tagName, attrSyntax.target);
}
}
Expand Down

0 comments on commit af12ed7

Please sign in to comment.