Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterAlfredLee committed Dec 16, 2021
1 parent 1e846a2 commit 4b24ab7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/vite-plugin-require-context/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default (options: PluginOptions = {}): Plugin => {
}
}

/**
* Handle the syntax in require.context(xxxxx).
* Considering the require.context may be called by another function, the calling may be like this:
* handRequireContext(require.context(dir, true, /*.vue/))
*
* It's not a easy work to get the xxxxx content in require.context using RegExp.
* So I'm using a stack to extract the content by comparing brackets.
*
* @param originalSyntax the original syntax content extracted by RegExp. There may be multi back brackets in the end of originalSyntax. e.g. (dir, true, /*.vue/))
*/
function handleRequireContextSyntax(originalSyntax: string) {
if (!originalSyntax.startsWith('require.context')) {
throw new Error(`Unexpected syntax met. Syntax does not start with 'require.context'`)
Expand Down

0 comments on commit 4b24ab7

Please sign in to comment.