Skip to content

Commit

Permalink
Fix regression in process plugin
Browse files Browse the repository at this point in the history
This was introduced in #715 by a wrong `String.prototype.replace´ to a
`while` loop conversion.
  • Loading branch information
marvinhagemeister committed Jul 5, 2021
1 parent d76a7f5 commit d94937f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/strange-olives-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

Fix `Cannot read property 'edit' of null` error. This was caused by a wrong alternative to substring matches of `String.prototype.replace`.
2 changes: 1 addition & 1 deletion packages/wmr/src/plugins/process-global-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function processGlobalPlugin({ NODE_ENV = 'development', env = {}
const reg = /typeof(\s+|\s*\(+\s*)process([^a-zA-Z$_])/g;
let match = null;
while ((match = reg.exec(code)) !== null) {
s.overwrite(match.index, match[0].length, 'typeof$1undefined$2');
s.overwrite(match.index, match.index + match[0].length, `typeof${match[1]}undefined${match[2]}`);
}

/** @type {*} */
Expand Down
9 changes: 9 additions & 0 deletions packages/wmr/test/fixtures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,15 @@ describe('fixtures', () => {
const output = await getOutput(env, instance);
expect(output).toMatch(/it works/i);
});

it('should deal with process evaluation', async () => {
await loadFixture('process-object', env);
instance = await runWmrFast(env.tmp.path);
await withLog(instance.output, async () => {
const output = await getOutput(env, instance);
expect(output).toMatch(/false/i);
});
});
});

describe('import.meta.env', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/wmr/test/fixtures/process-object/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<pre id="out"></pre>
<script src="./index.js" type="module"></script>
2 changes: 2 additions & 0 deletions packages/wmr/test/fixtures/process-object/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const result = typeof process === 'object' && 'development' === 'production';
document.getElementById('out').textContent = result;

0 comments on commit d94937f

Please sign in to comment.