Skip to content

Commit

Permalink
Treat getGlobalConfig().fastboot as dynamic as well
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Feb 27, 2024
1 parent 183dd97 commit e55b055
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 5 additions & 19 deletions packages/macros/src/babel/evaluate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,25 +409,11 @@ export class Evaluator {
: assertNever(maybeFastbootMemberExpression);

if (maybeFastbootProperty.isIdentifier() && maybeFastbootProperty.node.name === 'fastboot') {
let maybeIsRunningMemberExpression = maybeFastbootMemberExpression.parentPath;
if (
maybeIsRunningMemberExpression.isMemberExpression() ||
maybeIsRunningMemberExpression.isOptionalMemberExpression()
) {
let maybeIsRunningProperty = maybeIsRunningMemberExpression.isMemberExpression()
? maybeIsRunningMemberExpression.get('property')
: maybeIsRunningMemberExpression.isOptionalMemberExpression()
? maybeIsRunningMemberExpression.get('property')
: assertNever(maybeIsRunningMemberExpression);

if (maybeIsRunningProperty.isIdentifier() && maybeIsRunningProperty.node.name === 'isRunning') {
return {
confident: true,
value: getConfig(path, this.state, 'getGlobalConfig'),
hasRuntimeImplementation: true,
};
}
}
return {
confident: true,
value: getConfig(path, this.state, 'getGlobalConfig'),
hasRuntimeImplementation: true,
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/macros/tests/babel/eval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('hasRuntimeImplementation', function () {
let code = transform(`
import { getGlobalConfig } from '@embroider/macros';
const result = getGlobalConfig().fastboot`);
expect(code).toMatch(`result = false`);
expect(code).toMatch(`result = true`);
});

// fastboot.isRunning relies on dynamic evaluation at runtime. For backwards compatibility we keep it working. See https://github.com/embroider-build/embroider/issues/1804
Expand Down

0 comments on commit e55b055

Please sign in to comment.