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: 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;