Skip to content

Commit

Permalink
Fix AST transformation edge case
Browse files Browse the repository at this point in the history
When the AST transformer generates component invocation nodes, it would
handle numbers in paths incorrectly when generating pascal case.

Before: this-is-number-2 -> ThisIsNumber2
After:  this-is-number-2 -> ThisIsNumber_2
  • Loading branch information
DingoEatingFuzz committed Jan 25, 2023
1 parent 9d4ca98 commit 04bd352
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ order: 1

# Demo of DocfyLink component

This is a cool feature.

[Link from a demo](../docfy-output.md)

```hbs template
<div data-test-id="demo-1">
This is my Demo:
<span class='hyphenated-demo'>Assertable DOM node</span>
<DocfyLink @to={{this.url}}>My Link</DocfyLink>
</div>
<div data-test-id="demo-1-js-data">{{this.url}}</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/ember/src/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export function generateDemoComponentName(
.replace(/(\w)(\w*)/g, function (_, g1, g2) {
return `${g1.toUpperCase()}${g2.toLowerCase()}`;
})
.replace(/-(\d+)/g, function (_, g1) {
return `_${g1}`;
})
.replace(/-/g, '');

if (seenNames.has(dashCase)) {
Expand Down
12 changes: 12 additions & 0 deletions packages/ember/tests/acceptance/extracted-demos-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ module('Acceptance | extracted demos', function (hooks) {
.dom(snippet1)
.hasTextContaining('export default class MyDemo extends Component');
});

test('it correctly resolves demo components with hyphenated numbers', async function (assert) {
await visit('/docs/ember/components/docfy-with-hyphenated-number-2');

// Since this page has a hyphenated number in it, demo components must be transformed with
// preceding underscores like this:
// <DocfyDemoPackagesEmberComponentsDocfyWithHyphenatedNumber_2Demo1/>

assert
.dom('.docfy-demo__example .hyphenated-demo')
.hasText('Assertable DOM node');
});
});

0 comments on commit 04bd352

Please sign in to comment.