Skip to content

Commit

Permalink
#198: Added support for dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
petermasking committed Mar 8, 2023
1 parent f87f106 commit 1a7b415
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/jitar-reflection/src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ export default class Parser
{
return new ReflectionImport(members, token.value);
}
else if (token.hasValue(Group.OPEN))
{
token = tokenList.step(); // Read away the open group

const from = token.value;

tokenList.step(2); // Read away the from value and scope close

return new ReflectionImport(members, from);
}

if (token.hasValue(Scope.OPEN) === false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const IMPORTS =
IMPORT_DEFAULT_MEMBER: "import name, { member } from 'module'",
IMPORT_DEFAULT_MEMBER_AS: "import name, { member as alias } from 'module'",
IMPORT_MULTIPLE_MEMBERS_AS: "import { name, member as alias } from 'module'",
IMPORT_DYNAMIC: "import('module')",
}

const EXPORTS =
Expand Down
7 changes: 7 additions & 0 deletions packages/jitar-reflection/test/parser/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ describe('parser/Parser', () =>
expect(second.name).toBe('member');
expect(second.as).toBe('alias');
});

it('should parse importing modules dynamically', () =>
{
const imported = parser.parseImport(IMPORTS.IMPORT_DYNAMIC);
expect(imported.members.length).toBe(0);
expect(imported.from).toBe("'module'");
});
});

describe('.parseExport(code)', () =>
Expand Down

0 comments on commit 1a7b415

Please sign in to comment.