Skip to content

Commit

Permalink
Merge pull request #18 from stagas/fix-exports-array
Browse files Browse the repository at this point in the history
fix: support exports array access notation
  • Loading branch information
ygj6 authored Dec 29, 2021
2 parents 11f3602 + 551f1e1 commit ea65e69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/vite-plugin-commonjs/__tests__/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ test('require in comments', () => {
test('isCommonJS', () => {
expect(isCommonJS(`module.exports = {}`)).toBeTruthy();
expect(isCommonJS(`exports = { hello: false }`)).toBeTruthy();
expect(isCommonJS(`exports.foo = 1`)).toBeTruthy();
expect(isCommonJS(`exports[key] = 1`)).toBeTruthy();
expect(isCommonJS(`exports[1] = 1`)).toBeTruthy();
expect(isCommonJS(`exports['some key'] = 1`)).toBeTruthy();
});

test('Both url and comments are present', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-commonjs/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commonJSRegex: RegExp = /\b(module\.exports|exports\.\w+|exports\s*=\s*)/;
const commonJSRegex: RegExp = /\b(module\.exports|exports\.\w+|exports\s*=\s*|exports\s*\[.*\]\s*=\s*)/;
const requireRegex: RegExp = /_{0,2}require\s*\(\s*(["'].*?["'])\s*\)/g;
const IMPORT_STRING_PREFIX: String = "__require_for_vite";
const multilineCommentsRegex = /\/\*(.|[\r\n])*?\*\//gm
Expand Down

0 comments on commit ea65e69

Please sign in to comment.