Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/actions/check-public-api/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions build-packages/check-public-api/check-public-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ export declare type MyType = {value:string}

const dummyIndexFile = `export { o1 } from './bla';

export { o2, o3 } from './bla';
export { o4,

export { o2, o3 as o3$Some_thing } from './bla'; // :-) This is a comment
export { o4 as o4Something,
/****
* * This is a block comment **??? *
* **/
o5,o6,
o7} from './bla';
`;
8 changes: 6 additions & 2 deletions build-packages/check-public-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,17 @@ export function parseExportedObjectsInFile(
/**
* Parse a barrel file for the exported objects.
* It selects all string in \{\} e.g. export \{a,b,c\} from './xyz' will result in [a,b,c].
* /\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g - Matches single-line comments or multi-line comments or whitespaces.
* Aliases defined with 'as' keyword are removed.
* @param fileContent - Content of the index file to be parsed.
* @param regex - Regular expression used for matching exports.
* @returns List of objects exported by the given index file.
*/
export function parseBarrelFile(fileContent: string, regex: RegExp): string[] {
const normalized = fileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g, '');
// Remove block comments, single-line comments, 'as' keyword and aliases, and whitespace characters
const normalized = fileContent.replace(
/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g,
''
);
const groups = captureGroupsFromGlobalRegex(regex, normalized);

return flatten(groups.map(group => group.split(',')));
Expand Down
Loading