Skip to content

Commit

Permalink
fix: processing example is failing when example contains jsdoc annota…
Browse files Browse the repository at this point in the history
…ted export (#1170)

Fixes #1161

The code to process statements was making some incorrect assumptions
about how the AST looks like.
This fix is making it more resilient to unexpected AST structures.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Signed-off-by: Momo Kornher <kornherm@amazon.co.uk>
(cherry picked from commit b41e905)
  • Loading branch information
mrgrain committed Apr 23, 2024
1 parent 95e6218 commit 6cd28ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function sidelineImports(source: string): {
statement.kind === SyntaxKind.ImportDeclaration ||
statement.kind === SyntaxKind.ImportEqualsDeclaration ||
(statement.kind === SyntaxKind.VariableStatement &&
statement.getChildAt(0).getChildAt(0).kind === SyntaxKind.DeclareKeyword)
statement.getChildAt(0)?.getChildAt(0)?.kind === SyntaxKind.DeclareKeyword)
) {
imports += statement.getFullText(sourceFile);
} else {
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ const val = new Cls();
// Code snippet ended before !hide marker above
`);
});

// https://github.com/aws/jsii-rosetta/issues/1161
test('regression: can parse source with jsdoc annotated export', () => {
const snippet = {
visibleSource: `
/**
* JSDoc
*/
export const foo = "bar";
`,
location,
parameters: {
[SnippetParameters.$PROJECT_DIRECTORY]: 'test',
},
};

expect(fixturize(snippet)).toEqual(expect.objectContaining(snippet));
});
});

0 comments on commit 6cd28ce

Please sign in to comment.