Skip to content

Commit

Permalink
fix : handle undefined prop values
Browse files Browse the repository at this point in the history
  • Loading branch information
purohitdheeraj committed Dec 20, 2023
1 parent 9524ad7 commit f6f2a38
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions packages/babel-plugin/src/utils/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,25 @@ export default class StateManager {
}

get runtimeInjection(): ?$ReadOnly<{ from: string, as?: string }> {
const { runtimeInjection, rootDir } = this.options;
const filename = this.filename;

if (typeof runtimeInjection !== 'string') {
return runtimeInjection || null;
}

if (
runtimeInjection.startsWith('./') ||
runtimeInjection.startsWith('../')
) {
const absolutePath = path.join(rootDir, runtimeInjection);
return { from: absolutePath };
}
const { runtimeInjection, rootDir, filename } = this.options || {};

if (typeof runtimeInjection === 'string' && rootDir && filename) {
if (
runtimeInjection.startsWith('./') ||
runtimeInjection.startsWith('../')
) {
const absolutePath = path.join(rootDir, runtimeInjection);
return { from: absolutePath };
}

if (path.isAbsolute(runtimeInjection) && filename !== null) {
const relativePath = path.relative(
path.dirname(filename),
runtimeInjection,
);
return { from: relativePath };
}

return { from: runtimeInjection };
return runtimeInjection || null;
}

get isDev(): boolean {
Expand Down

0 comments on commit f6f2a38

Please sign in to comment.