Skip to content

Commit

Permalink
refactor(yieldContextExtractor): fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
camerondubas committed Oct 2, 2023
1 parent 1a5154c commit c05e246
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/utils/yield-context-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function extractYieldMetadata(template: ASTv1.Template) {
const acc: Record<string, unknown> = {};

return {
$elemant: node.tag,
$element: node.tag,
$attributes: this.map(node.attributes).reduce((acc, [key, val]) => {
Object.defineProperty(acc, key, {
value: val,
Expand All @@ -79,12 +79,12 @@ export function extractYieldMetadata(template: ASTv1.Template) {
return acc;
}, acc),
$modifiers: this.map(node.modifiers),
$programms: this.map(node.children).filter((e) => typeof e !== 'string'),
$programs: this.map(node.children).filter((e) => typeof e !== 'string'),

Check warning on line 82 in src/utils/yield-context-extractor.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/yield-context-extractor.ts#L82

Added line #L82 was not covered by tests
};
}
Template(node: ASTv1.Template | ASTv1.Program) {
return {
$programms: this.map(node.body).filter((e) => typeof e !== 'string'),
$programs: this.map(node.body).filter((e) => typeof e !== 'string'),
};
}
ConcatStatement(node: ASTv1.ConcatStatement) {
Expand Down Expand Up @@ -137,14 +137,14 @@ export function extractYieldMetadata(template: ASTv1.Template) {
BlockStatement(node: ASTv1.BlockStatement) {
const result = this.SubExpression(node);

const $programms = [this.Block(node.program)];
const $programs = [this.Block(node.program)];

Check warning on line 140 in src/utils/yield-context-extractor.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/yield-context-extractor.ts#L140

Added line #L140 was not covered by tests

if (node.inverse) {
$programms.push(this.Block(node.inverse));
$programs.push(this.Block(node.inverse));

Check warning on line 143 in src/utils/yield-context-extractor.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/yield-context-extractor.ts#L143

Added line #L143 was not covered by tests
}

Object.defineProperty(result, '$programms', {
value: $programms,
Object.defineProperty(result, '$programs', {

Check warning on line 146 in src/utils/yield-context-extractor.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/yield-context-extractor.ts#L146

Added line #L146 was not covered by tests
value: $programs,
});

return result;
Expand Down
24 changes: 22 additions & 2 deletions test/utils/yield-context-extractor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function extract(tpl: string) {
return extractYieldMetadata(preprocess(tpl));
}

describe('Yeld Metadata API', () => {
describe('Yield Metadata API', () => {
it('should handle default yield with hash', () => {
expect(
extract(`
Expand Down Expand Up @@ -91,7 +91,27 @@ describe('Yeld Metadata API', () => {
`)
).toEqual({ 'default:0:': ['component', 'foo-bar'], 'default:1:': ['component', 'foo-baz'] });
});
it('should handle default yeld with single positional hash argument with component property', () => {
it('should handle default yield with single positional hash argument with component property', () => {
expect(extract(`{{yield (hash Foo=(component "my-component"))}}`)).toEqual({ 'default:0:Foo': ['component', 'my-component'] });
});
it('should extract only yield content when nested in a div with other content', () => {
expect(
extract(`
<div class="example">
<p>Some Content</p>
{{yield (hash Foo=(component "my-component"))}}
</div>
`)
).toEqual({ 'default:0:Foo': ['component', 'my-component'] });
});

it('should extract only yield content when nested in an "if" statement', () => {
expect(
extract(`
{{#if this.isTrue}}
{{yield (hash Foo=(component "my-component"))}}
{{/if}}
`)
).toEqual({ 'default:0:Foo': ['component', 'my-component'] });
});
});

0 comments on commit c05e246

Please sign in to comment.