Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 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
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ There are helpers for many of these functions, which will resolve this for you:
If your tests can't or aren't covered by a helper, one common solution is the use of `DEBUG` flag. Wrapping the debug-only dependent test in a check of this flag will cause that test to not be run in the prod test suite:

```javascript
import { DEBUG } from '@glimmer/env';

if (DEBUG) {
if (import.meta.env?.DEV ?? true) {
// Development-only test goes here
}
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,4 @@
}
},
"packageManager": "pnpm@10.5.0"
}
}
14 changes: 7 additions & 7 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import { setOwner } from '@ember/-internals/owner';
import { dictionary } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { DebugRegistry } from './registry';
import type Registry from './registry';

Expand All @@ -24,7 +24,7 @@ declare const gc: undefined | (() => void);

let leakTracking: LeakTracking;
let containers: WeakSet<Container>;
if (DEBUG) {
if (import.meta.env?.DEV) {
// requires v8
// chrome --js-flags="--allow-natives-syntax --expose-gc"
// node --allow-natives-syntax --expose-gc
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class Container {
this.isDestroyed = false;
this.isDestroying = false;

if (DEBUG) {
if (import.meta.env?.DEV) {
this.validationCache = dictionary(options.validationCache || null);
if (containers !== undefined) {
containers.add(this);
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class Container {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
Container._leakTracking = leakTracking!;
}

Expand Down Expand Up @@ -312,13 +312,13 @@ function factoryFor(
return;
}

if (DEBUG && factory && typeof factory._onLookup === 'function') {
if (import.meta.env?.DEV && factory && typeof factory._onLookup === 'function') {
factory._onLookup(fullName);
}

let manager = new InternalFactoryManager(container, factory, fullName, normalizedName);

if (DEBUG) {
if (import.meta.env?.DEV) {
manager = wrapManagerInDeprecationProxy(manager);
}

Expand Down Expand Up @@ -541,7 +541,7 @@ export class InternalFactoryManager<
setOwner(props, container.owner!);
setFactoryFor(props, this);

if (DEBUG) {
if (import.meta.env?.DEV) {
let lazyInjections;
let validationCache = this.container.validationCache;
// Ensure that all lazy injections are valid at instantiation time
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/container/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { dictionary, intern } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import type { set } from '@ember/object';
import { DEBUG } from '@glimmer/env';

import type { ContainerOptions, LazyInjection } from './container';
import Container from './container';

Expand Down Expand Up @@ -468,7 +468,7 @@ export declare class DebugRegistry extends Registry {
validateInjections(injections: Injection[]): void;
}

if (DEBUG) {
if (import.meta.env?.DEV) {
const proto = Registry.prototype as DebugRegistry;
proto.normalizeInjectionsHash = function (hash: { [key: string]: LazyInjection }) {
let injections: Injection[] = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/container/tests/container_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getOwner } from '@ember/-internals/owner';
import Service from '@ember/service';
import { DEBUG } from '@glimmer/env';

import { Registry } from '..';
import { factory, moduleFor, AbstractTestCase, runTask } from 'internal-test-helpers';

Expand Down Expand Up @@ -447,7 +447,7 @@ moduleFor(
}

['@test Lazy injection validations are cached'](assert) {
if (!DEBUG) {
if (!import.meta.env?.DEV) {
assert.expect(0);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/@ember/-internals/environment/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DEBUG } from '@glimmer/env';
import global from './global';

/**
Expand Down Expand Up @@ -91,7 +90,7 @@ export const ENV = {
@default false
@private
*/
_DEBUG_RENDER_TREE: DEBUG,
_DEBUG_RENDER_TREE: import.meta.env?.DEV,

/**
Whether to force all deprecations to be enabled. This is used internally by
Expand Down Expand Up @@ -200,7 +199,7 @@ export const ENV = {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
ENV._DEBUG_RENDER_TREE = true;
}
})(global.EmberENV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { addChildView, setElementView, setViewElement } from '@ember/-internals/
import type { Nullable } from '@ember/-internals/utility-types';
import { assert, debugFreeze } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';

import type {
Bounds,
CapturedArguments,
Expand Down Expand Up @@ -337,7 +337,7 @@ export default class CurlyComponentManager
bucket.classRef = args.named.get('class');
}

if (DEBUG) {
if (import.meta.env?.DEV) {
processComponentInitializationAssertions(component, props);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFactoryFor } from '@ember/-internals/container';
import { assert } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';

import type {
ComponentDefinition,
Environment,
Expand Down Expand Up @@ -57,7 +57,7 @@ class RootComponentManager extends CurlyComponentManager {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
processComponentInitializationAssertions(component, {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
WithCustomDebugRenderTree,
} from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { DEBUG } from '@glimmer/env';

import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createDebugAliasRef, valueForRef } from '@glimmer/reference';
Expand Down Expand Up @@ -61,7 +61,7 @@ class RouteTemplateManager
): RouteTemplateInstanceState {
let self = args.named.get('controller');

if (DEBUG) {
if (import.meta.env?.DEV) {
self = createDebugAliasRef!('this', self);
}

Expand Down
9 changes: 7 additions & 2 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@ember/-internals/views';
import { guidFor } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { Environment, Template, TemplateFactory } from '@glimmer/interfaces';
import { setInternalComponentManager } from '@glimmer/manager';
import { isUpdatableRef, updateRef } from '@glimmer/reference';
Expand Down Expand Up @@ -939,7 +939,12 @@ class Component<S = unknown>
}
}

if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
if (
import.meta.env?.DEV &&
eventDispatcher &&
this.renderer._isInteractive &&
this.tagName === ''
) {
let eventNames = [];
let events = eventDispatcher.finalEventNameMapping;

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type EngineInstance from '@ember/engine/instance';
import { flaggedInstrument } from '@ember/instrumentation';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { DEBUG } from '@glimmer/env';

import type { Maybe } from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { consumeTag, createCache, getValue, tagFor, untrack } from '@glimmer/validator';
Expand Down Expand Up @@ -344,7 +344,7 @@ class _LinkTo extends InternalComponent {
// TODO: can we narrow this down to QP changes only?
consumeTag(tagFor(routing, 'currentState'));

if (DEBUG) {
if (import.meta.env?.DEV) {
try {
return routing.generateURL(route, models, query);
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { constructStyleDeprecationMessage } from '@ember/-internals/views';
import { assert, deprecate, warn } from '@ember/debug';
import type { DeprecationOptions } from '@ember/debug';
import { schedule, _backburner } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';

import setGlobalContext from '@glimmer/global-context';
import type { EnvironmentDelegate } from '@glimmer/runtime';
import { debug } from '@glimmer/validator';
Expand Down Expand Up @@ -57,7 +57,7 @@ setGlobalContext({
},

assert(test: unknown, msg: string, options?: { id: string }) {
if (DEBUG) {
if (import.meta.env?.DEV) {
let id = options?.id;

let override = VM_ASSERTION_OVERRIDES.filter((o) => o.id === id)[0];
Expand All @@ -67,7 +67,7 @@ setGlobalContext({
},

deprecate(msg: string, test: unknown, options: { id: string }) {
if (DEBUG) {
if (import.meta.env?.DEV) {
let { id } = options;

if (id === 'argument-less-helper-paren-less-invocation') {
Expand All @@ -91,7 +91,7 @@ setGlobalContext({
},
});

if (DEBUG) {
if (import.meta.env?.DEV) {
debug?.setTrackingTransactionEnv?.({
debugMessage(obj, keyName) {
let dirtyString = keyName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { CapturedArguments, Helper } from '@glimmer/interfaces';
import { createComputeRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';

let helper: Helper;

if (DEBUG) {
if (import.meta.env?.DEV) {
helper = (args: CapturedArguments) => {
const inner = args.positional[0];
assert('expected at least one positional arg', inner);
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { FullName, InternalOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { CapturedArguments } from '@glimmer/interfaces';
import { createConstRef, isConstRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';
Expand All @@ -30,7 +30,7 @@ export default internalHelper(
((s: string): s is FullName => s.split(':').length === 2)(fullName)
);

if (DEBUG) {
if (import.meta.env?.DEV) {
let [type, name] = fullName.split(':');

assert(
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isDestroying,
registerDestructor,
} from '@glimmer/destroyable';
import { DEBUG } from '@glimmer/env';

import type {
Bounds,
Cursor,
Expand Down Expand Up @@ -108,7 +108,7 @@ const NO_OP = () => {};
// during render. This prevents infinite revalidation type loops from occuring,
// and ensures that errors are not swallowed by subsequent follow on failures.
function errorLoopTransaction(fn: () => void) {
if (DEBUG) {
if (import.meta.env?.DEV) {
return () => {
let didError = true;

Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { InternalFactory, InternalOwner } from '@ember/-internals/owner';
import { isFactory } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';

import type {
ClassicResolver,
HelperDefinitionState,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const BUILTIN_HELPERS: Record<string, object> = {
'unique-id': uniqueId,
};

if (DEBUG) {
if (import.meta.env?.DEV) {
BUILTIN_HELPERS['-disallow-dynamic-resolution'] = disallowDynamicResolution;
} else {
// Bug: this may be a quirk of our test setup?
Expand Down Expand Up @@ -171,8 +171,8 @@ export default class ResolverImpl implements ClassicResolver<InternalOwner> {
// than the raw value (`factoryFor(...).class`). This is because injections are already
// bound in the factoryFor result, including type-based injections

if (DEBUG) {
// In DEBUG we need to only set the associated value once, otherwise
if (import.meta.env?.DEV) {
// In import.meta.env?.DEV we need to only set the associated value once, otherwise
// we'll trigger an assertion
if (!CLASSIC_HELPER_MANAGER_ASSOCIATED.has(factory)) {
CLASSIC_HELPER_MANAGER_ASSOCIATED.add(factory);
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/syntax/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { InternalOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { Nullable } from '@ember/-internals/utility-types';
import type { CapturedArguments, CurriedComponent } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
Expand Down Expand Up @@ -64,7 +64,7 @@ export const mountHelper = internalHelper(
args.positional.length === 1
);

if (DEBUG && args.named) {
if (import.meta.env?.DEV && args.named) {
let keys = Object.keys(args.named);
let extra = keys.filter((k) => k !== 'model');

Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/syntax/outlet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { InternalOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type {
CapturedArguments,
CurriedComponent,
Expand Down Expand Up @@ -100,7 +100,7 @@ export const outletHelper = internalHelper(
if (hasInternalComponentManager(template)) {
component = template;
} else {
if (DEBUG) {
if (import.meta.env?.DEV) {
// We don't appear to have a standard way or a brand to check, but for the
// purpose of avoiding obvious user errors, this probably gets you close
// enough.
Expand Down Expand Up @@ -163,7 +163,7 @@ export const outletHelper = internalHelper(
return model;
});

if (DEBUG) {
if (import.meta.env?.DEV) {
named['model'] = createDebugAliasRef!('@model', named['model']);
}

Expand Down
Loading
Loading