Skip to content

Commit 68dcc15

Browse files
committed
fix(replace): objectGuards doesn't take effects
BREAKING CHANGES: Fixed the problem that the objectGuards option did not take effect, so the bundle results before and after may be inconsistent
1 parent 8550c4b commit 68dcc15

File tree

4 files changed

+4
-20
lines changed

4 files changed

+4
-20
lines changed

packages/replace/src/index.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,10 @@ function expandTypeofReplacements(replacements) {
4343
const objMatch = key.match(objKeyRegEx);
4444
if (!objMatch) return;
4545
let dotIndex = objMatch[1].length;
46-
let lastIndex = 0;
4746
do {
4847
// eslint-disable-next-line no-param-reassign
49-
replacements[`typeof ${key.slice(lastIndex, dotIndex)} ===`] = '"object" ===';
50-
// eslint-disable-next-line no-param-reassign
51-
replacements[`typeof ${key.slice(lastIndex, dotIndex)} !==`] = '"object" !==';
52-
// eslint-disable-next-line no-param-reassign
53-
replacements[`typeof ${key.slice(lastIndex, dotIndex)}===`] = '"object"===';
54-
// eslint-disable-next-line no-param-reassign
55-
replacements[`typeof ${key.slice(lastIndex, dotIndex)}!==`] = '"object"!==';
56-
// eslint-disable-next-line no-param-reassign
57-
replacements[`typeof ${key.slice(lastIndex, dotIndex)} ==`] = '"object" ===';
58-
// eslint-disable-next-line no-param-reassign
59-
replacements[`typeof ${key.slice(lastIndex, dotIndex)} !=`] = '"object" !==';
60-
// eslint-disable-next-line no-param-reassign
61-
replacements[`typeof ${key.slice(lastIndex, dotIndex)}==`] = '"object"===';
62-
// eslint-disable-next-line no-param-reassign
63-
replacements[`typeof ${key.slice(lastIndex, dotIndex)}!=`] = '"object"!==';
64-
lastIndex = dotIndex + 1;
65-
dotIndex = key.indexOf('.', lastIndex);
48+
replacements[`typeof ${key.slice(0, dotIndex)}`] = '"object"';
49+
dotIndex = key.indexOf('.', dotIndex + 1);
6650
} while (dotIndex !== -1);
6751
});
6852
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
1+
if (typeof process !== 'undefined' && typeof process.env === "object" && process.env.NODE_ENV === 'production') {
22
console.log('production');
33
}

packages/replace/test/snapshots/form.js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Generated by [AVA](https://avajs.dev).
4343

4444
> Snapshot 1
4545
46-
`if (typeof process !== 'undefined' && "production" === 'production') {␊
46+
`if ("object" !== 'undefined' && "object" === "object" && "production" === 'production') {␊
4747
console.log('production');␊
4848
}`
4949

7 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)