Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replace): objectGuards doesn't take effects #1764

Merged
merged 2 commits into from
Sep 23, 2024
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
20 changes: 2 additions & 18 deletions packages/replace/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,10 @@ function expandTypeofReplacements(replacements) {
const objMatch = key.match(objKeyRegEx);
if (!objMatch) return;
let dotIndex = objMatch[1].length;
let lastIndex = 0;
do {
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)} ===`] = '"object" ===';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)} !==`] = '"object" !==';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)}===`] = '"object"===';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)}!==`] = '"object"!==';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)} ==`] = '"object" ===';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)} !=`] = '"object" !==';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)}==`] = '"object"===';
// eslint-disable-next-line no-param-reassign
replacements[`typeof ${key.slice(lastIndex, dotIndex)}!=`] = '"object"!==';
lastIndex = dotIndex + 1;
dotIndex = key.indexOf('.', lastIndex);
replacements[`typeof ${key.slice(0, dotIndex)}`] = '"object"';
dotIndex = key.indexOf('.', dotIndex + 1);
} while (dotIndex !== -1);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
if (typeof process !== 'undefined' && typeof process.env === "object" && process.env.NODE_ENV === 'production') {
console.log('production');
}
2 changes: 1 addition & 1 deletion packages/replace/test/snapshots/form.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1

`if (typeof process !== 'undefined' && "production" === 'production') {␊
`if ("object" !== 'undefined' && "object" === "object" && "production" === 'production') {␊
console.log('production');␊
}`

Expand Down
Binary file modified packages/replace/test/snapshots/form.js.snap
Binary file not shown.
Loading