diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0e52f727747..cdb0244e923 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -273,12 +273,10 @@ If your build is failing on the 'production' suite, you may be relying on a debu There are helpers for many of these functions, which will resolve this for you: `expectDeprecation`, `expectAssertion`, etc. Please use these helpers when dealing with these functions. -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: +If your tests can't or aren't covered by a helper, one common solution is the use of `import.meta.env?.DEV` 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 } ``` diff --git a/babel.test.config.mjs b/babel.test.config.mjs index e270383106a..03b77d1f347 100644 --- a/babel.test.config.mjs +++ b/babel.test.config.mjs @@ -12,8 +12,6 @@ import baseConfig from './babel.config.mjs'; // eslint-disable-next-line no-redeclare const require = createRequire(import.meta.url); -const buildDebugMacroPlugin = require('./broccoli/build-debug-macro-plugin.js'); -const isProduction = process.env.EMBER_ENV === 'production'; export default { ...baseConfig, @@ -27,5 +25,5 @@ export default { ], ], - plugins: [...baseConfig.plugins, buildDebugMacroPlugin(!isProduction)], + plugins: [...baseConfig.plugins], }; diff --git a/broccoli/build-debug-macro-plugin.js b/broccoli/build-debug-macro-plugin.js deleted file mode 100644 index 0b7b9363ea2..00000000000 --- a/broccoli/build-debug-macro-plugin.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function buildDebugMacrosPlugin(isDebug) { - return [ - require.resolve('babel-plugin-debug-macros'), - { - debugTools: { - source: '@ember/debug', - assertPredicateIndex: 1, - isDebug, - }, - externalizeHelpers: { - module: true, - }, - flags: [{ source: '@glimmer/env', flags: { DEBUG: isDebug } }], - }, - ]; -}; diff --git a/broccoli/import-meta.js b/broccoli/import-meta.js new file mode 100644 index 00000000000..2d87a3748b2 --- /dev/null +++ b/broccoli/import-meta.js @@ -0,0 +1,25 @@ +function hasDEV(code) { + return code.includes('import.meta.env?.DEV') || code.includes('import.meta.env.DEV'); +} +export function importMetaRemoval(debugMacrosMode) { + return { + name: 'define custom import.meta.env', + async transform(code) { + if (debugMacrosMode === true) { + if (hasDEV(code)) { + return code.replace(/import.meta.env\??.DEV/g, 'true'); + } + + return; + } + + if (debugMacrosMode === false) { + if (hasDEV(code)) { + return code.replace(/import.meta.env\??.DEV/g, 'false'); + } + } + + return undefined; + }, + }; +} diff --git a/package.json b/package.json index 97b545d7f6e..f44f0598b94 100644 --- a/package.json +++ b/package.json @@ -390,4 +390,4 @@ } }, "packageManager": "pnpm@10.5.0" -} +} \ No newline at end of file diff --git a/packages/@ember/-internals/container/lib/container.ts b/packages/@ember/-internals/container/lib/container.ts index 0705d2ee2de..4a9dfe95be9 100644 --- a/packages/@ember/-internals/container/lib/container.ts +++ b/packages/@ember/-internals/container/lib/container.ts @@ -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'; @@ -24,7 +24,7 @@ declare const gc: undefined | (() => void); let leakTracking: LeakTracking; let containers: WeakSet; -if (DEBUG) { +if (import.meta.env?.DEV) { // requires v8 // chrome --js-flags="--allow-natives-syntax --expose-gc" // node --allow-natives-syntax --expose-gc @@ -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); @@ -232,7 +232,7 @@ export default class Container { } } -if (DEBUG) { +if (import.meta.env?.DEV) { Container._leakTracking = leakTracking!; } @@ -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); } @@ -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 diff --git a/packages/@ember/-internals/container/lib/registry.ts b/packages/@ember/-internals/container/lib/registry.ts index 81111ab2ff7..3547b684099 100644 --- a/packages/@ember/-internals/container/lib/registry.ts +++ b/packages/@ember/-internals/container/lib/registry.ts @@ -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'; @@ -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[] = []; diff --git a/packages/@ember/-internals/container/tests/container_test.js b/packages/@ember/-internals/container/tests/container_test.js index 3417252bab5..6127946d5fb 100644 --- a/packages/@ember/-internals/container/tests/container_test.js +++ b/packages/@ember/-internals/container/tests/container_test.js @@ -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'; @@ -447,7 +447,7 @@ moduleFor( } ['@test Lazy injection validations are cached'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/environment/lib/env.ts b/packages/@ember/-internals/environment/lib/env.ts index b71f02d9702..2902456b183 100644 --- a/packages/@ember/-internals/environment/lib/env.ts +++ b/packages/@ember/-internals/environment/lib/env.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import global from './global'; /** @@ -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 @@ -200,7 +199,7 @@ export const ENV = { } } - if (DEBUG) { + if (import.meta.env?.DEV) { ENV._DEBUG_RENDER_TREE = true; } })(global.EmberENV); diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts index 0b0da6ec97d..6dbc0d47ef4 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts @@ -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, @@ -337,7 +337,7 @@ export default class CurlyComponentManager bucket.classRef = args.named.get('class'); } - if (DEBUG) { + if (import.meta.env?.DEV) { processComponentInitializationAssertions(component, props); } diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/root.ts b/packages/@ember/-internals/glimmer/lib/component-managers/root.ts index 00aca8f633c..3b82b2e898b 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/root.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/root.ts @@ -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, @@ -57,7 +57,7 @@ class RootComponentManager extends CurlyComponentManager { } } - if (DEBUG) { + if (import.meta.env?.DEV) { processComponentInitializationAssertions(component, {}); } diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/route-template.ts b/packages/@ember/-internals/glimmer/lib/component-managers/route-template.ts index 10f291d7dfe..316dffab359 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/route-template.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/route-template.ts @@ -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'; @@ -61,7 +61,7 @@ class RouteTemplateManager ): RouteTemplateInstanceState { let self = args.named.get('controller'); - if (DEBUG) { + if (import.meta.env?.DEV) { self = createDebugAliasRef!('this', self); } diff --git a/packages/@ember/-internals/glimmer/lib/component.ts b/packages/@ember/-internals/glimmer/lib/component.ts index e4dbf48c09c..6a577629500 100644 --- a/packages/@ember/-internals/glimmer/lib/component.ts +++ b/packages/@ember/-internals/glimmer/lib/component.ts @@ -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'; @@ -939,7 +939,12 @@ class Component } } - 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; diff --git a/packages/@ember/-internals/glimmer/lib/components/link-to.ts b/packages/@ember/-internals/glimmer/lib/components/link-to.ts index 3e806051d0e..789d6342b4f 100644 --- a/packages/@ember/-internals/glimmer/lib/components/link-to.ts +++ b/packages/@ember/-internals/glimmer/lib/components/link-to.ts @@ -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'; @@ -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) { diff --git a/packages/@ember/-internals/glimmer/lib/environment.ts b/packages/@ember/-internals/glimmer/lib/environment.ts index 5abd58c2bc6..81bd534b179 100644 --- a/packages/@ember/-internals/glimmer/lib/environment.ts +++ b/packages/@ember/-internals/glimmer/lib/environment.ts @@ -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'; @@ -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]; @@ -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') { @@ -91,7 +91,7 @@ setGlobalContext({ }, }); -if (DEBUG) { +if (import.meta.env?.DEV) { debug?.setTrackingTransactionEnv?.({ debugMessage(obj, keyName) { let dirtyString = keyName diff --git a/packages/@ember/-internals/glimmer/lib/helpers/-in-element-null-check.ts b/packages/@ember/-internals/glimmer/lib/helpers/-in-element-null-check.ts index 10fc222f5fe..c01b0e275dd 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/-in-element-null-check.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/-in-element-null-check.ts @@ -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); diff --git a/packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts b/packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts index 71bd9f3ff43..a3bc57fbdfb 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts @@ -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'; @@ -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( diff --git a/packages/@ember/-internals/glimmer/lib/renderer.ts b/packages/@ember/-internals/glimmer/lib/renderer.ts index 2a0847d4818..53bec066d14 100644 --- a/packages/@ember/-internals/glimmer/lib/renderer.ts +++ b/packages/@ember/-internals/glimmer/lib/renderer.ts @@ -13,7 +13,7 @@ import { isDestroying, registerDestructor, } from '@glimmer/destroyable'; -import { DEBUG } from '@glimmer/env'; + import type { Bounds, Cursor, @@ -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; diff --git a/packages/@ember/-internals/glimmer/lib/resolver.ts b/packages/@ember/-internals/glimmer/lib/resolver.ts index e6517bc3e88..b2cff0529a8 100644 --- a/packages/@ember/-internals/glimmer/lib/resolver.ts +++ b/packages/@ember/-internals/glimmer/lib/resolver.ts @@ -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, @@ -111,7 +111,7 @@ export const BUILTIN_HELPERS: Record = { '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? @@ -171,8 +171,8 @@ export default class ResolverImpl implements ClassicResolver { // 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 DEV mode 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); diff --git a/packages/@ember/-internals/glimmer/lib/syntax/mount.ts b/packages/@ember/-internals/glimmer/lib/syntax/mount.ts index eef12143582..a735e0c075f 100644 --- a/packages/@ember/-internals/glimmer/lib/syntax/mount.ts +++ b/packages/@ember/-internals/glimmer/lib/syntax/mount.ts @@ -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'; @@ -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'); diff --git a/packages/@ember/-internals/glimmer/lib/syntax/outlet.ts b/packages/@ember/-internals/glimmer/lib/syntax/outlet.ts index c4f6909a579..0f2bbc0b9fe 100644 --- a/packages/@ember/-internals/glimmer/lib/syntax/outlet.ts +++ b/packages/@ember/-internals/glimmer/lib/syntax/outlet.ts @@ -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, @@ -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. @@ -163,7 +163,7 @@ export const outletHelper = internalHelper( return model; }); - if (DEBUG) { + if (import.meta.env?.DEV) { named['model'] = createDebugAliasRef!('@model', named['model']); } diff --git a/packages/@ember/-internals/glimmer/lib/utils/debug-render-message.ts b/packages/@ember/-internals/glimmer/lib/utils/debug-render-message.ts index 9ef9c7f4bb2..4163cbe1507 100644 --- a/packages/@ember/-internals/glimmer/lib/utils/debug-render-message.ts +++ b/packages/@ember/-internals/glimmer/lib/utils/debug-render-message.ts @@ -1,8 +1,6 @@ -import { DEBUG } from '@glimmer/env'; - let debugRenderMessage: undefined | ((renderingStack: string) => string); -if (DEBUG) { +if (import.meta.env?.DEV) { debugRenderMessage = (renderingStack: string) => { return `While rendering:\n----------------\n${renderingStack.replace(/^/gm, ' ')}`; }; diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/component-template-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/component-template-test.js index 64a814edd5c..32219b62570 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/component-template-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/component-template-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; import { setComponentTemplate, getComponentTemplate } from '@glimmer/manager'; @@ -22,7 +21,7 @@ moduleFor( } '@test calling it with primitives asserts'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -57,7 +56,7 @@ moduleFor( } '@test calling it twice on the same object asserts'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js index ffc53313e27..a0662528085 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'internal-test-helpers'; import { isEmpty } from '@ember/utils'; @@ -586,7 +585,7 @@ moduleFor( } ['@test raises an assertion when component path is not a component name (static)'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -597,7 +596,7 @@ moduleFor( } ['@test raises an assertion when component path is not a component name (dynamic)'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js index 2bf955d092e..ef419ee55ed 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js @@ -11,7 +11,7 @@ import { import { action } from '@ember/object'; import { run } from '@ember/runloop'; -import { DEBUG } from '@glimmer/env'; + import { tracked } from '@ember/-internals/metal'; import { alias } from '@ember/object/computed'; import { on } from '@ember/object/evented'; @@ -98,7 +98,7 @@ moduleFor( content: 'blahzorz', }); - if (DEBUG) { + if (import.meta.env?.DEV) { let willThrow = () => run(null, set, component, 'elementId', 'herpyderpy'); assert.throws(willThrow, /Changing a view's elementId after creation is not allowed/); diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js index f43968b9047..4de4352a0c9 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; import { set, computed } from '@ember/object'; @@ -473,7 +472,7 @@ moduleFor( } ['@test component with dynamic name argument resolving to non-existent component'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -486,7 +485,7 @@ moduleFor( } ['@test component with static name argument for non-existent component'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/error-handling-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/error-handling-test.js index bbb53a2631d..71417abefda 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/error-handling-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/error-handling-test.js @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; import { set } from '@ember/object'; @@ -47,7 +45,7 @@ moduleFor( runTask(() => set(this.context, 'switch', true)); - if (DEBUG) { + if (import.meta.env?.DEV) { this.assertText('', 'it does not rerender after error in development'); } else { this.assertText('hello', 'it rerenders after error in production'); @@ -99,7 +97,7 @@ moduleFor( runTask(() => set(this.context, 'switch', true)); - if (DEBUG) { + if (import.meta.env?.DEV) { this.assertText('', 'it does not rerender after error in development'); } else { this.assertText('hello', 'it does rerender after error in production'); diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-angle-test.js index f52dbd21ff6..705b3882b83 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-angle-test.js @@ -9,7 +9,6 @@ import Router from '@ember/routing/router'; import Route from '@ember/routing/route'; import Controller from '@ember/controller'; import { set } from '@ember/object'; -import { DEBUG } from '@glimmer/env'; moduleFor( ' component (rendering tests)', @@ -26,7 +25,7 @@ moduleFor( async [`@test it throws a useful error if you pass the href argument`](assert) { this.addTemplate('application', `Index`); - if (DEBUG) { + if (import.meta.env?.DEV) { await assert.rejects( this.visit('/'), /Passing the `@href` argument to is not supported\./ diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-curly-test.js index 1cd6dd80ff0..48dc118ccb6 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/rendering-curly-test.js @@ -2,7 +2,6 @@ import { moduleFor, ApplicationTestCase, RenderingTestCase, runTask } from 'inte import Controller from '@ember/controller'; import { set } from '@ember/object'; -import { DEBUG } from '@glimmer/env'; moduleFor( '{{link-to}} component (rendering tests)', @@ -10,7 +9,7 @@ moduleFor( async [`@test it throws a useful error if you invoke it wrong`](assert) { this.addTemplate('application', `{{#link-to}}Index{{/link-to}}`); - if (DEBUG) { + if (import.meta.env?.DEV) { await assert.rejects( this.visit('/'), /You must provide at least one of the `@route`, `@model`, `@models` or `@query` arguments to ``./ @@ -23,7 +22,7 @@ moduleFor( async [`@test it throws a useful error if you pass the href argument`](assert) { this.addTemplate('application', `{{#link-to href="nope" route="index"}}Index{{/link-to}}`); - if (DEBUG) { + if (import.meta.env?.DEV) { await assert.rejects( this.visit('/'), /Passing the `@href` argument to is not supported\./ diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js index d35deff907b..f183358baa8 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js @@ -11,7 +11,7 @@ import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import { service } from '@ember/service'; import Engine from '@ember/engine'; -import { DEBUG } from '@glimmer/env'; + import { compile } from '../../../utils/helpers'; // IE includes the host name @@ -1594,7 +1594,7 @@ moduleFor( } async [`@test it throws a useful error if you invoke it wrong`](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js index 76e42f53e53..90f3477addc 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js @@ -11,7 +11,7 @@ import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import { service } from '@ember/service'; import Engine from '@ember/engine'; -import { DEBUG } from '@glimmer/env'; + import { compile } from '../../../utils/helpers'; // IE includes the host name @@ -1496,7 +1496,7 @@ moduleFor( } async [`@test it throws a useful error if you invoke it wrong`](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/content-test.js b/packages/@ember/-internals/glimmer/tests/integration/content-test.js index 2e3c96609f8..3170809ffb0 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/content-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/content-test.js @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - import { RenderingTestCase, moduleFor, applyMixins, classes, runTask } from 'internal-test-helpers'; import { set, computed } from '@ember/object'; @@ -1694,7 +1692,7 @@ moduleFor( } ); -if (DEBUG) { +if (import.meta.env?.DEV) { moduleFor( 'Inline style tests - warnings', class extends StyleTest { diff --git a/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js b/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js index 95ce65ba453..684e3fb3d74 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, runTask, strip } from 'internal-test-helpers'; import { componentCapabilities } from '@glimmer/manager'; @@ -525,7 +524,7 @@ moduleFor( } '@test capabilities helper function must be used to generate capabilities'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -841,7 +840,7 @@ moduleFor( } '@test capabilities helper function must be used to generate capabilities'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js b/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js index d5ca43618d0..ea027f4b401 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, @@ -15,7 +14,7 @@ import { backtrackingMessageFor } from '../utils/debug-stack'; class ModifierManagerTest extends RenderingTestCase { '@test throws a useful error when missing capabilities'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -283,7 +282,7 @@ class ModifierManagerTest extends RenderingTestCase { } '@test capabilities helper function must be used to generate capabilities'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -483,7 +482,7 @@ moduleFor( defineSimpleModifier((element) => (element.innerHTML = 'Hello, world!')) ); - if (DEBUG) { + if (import.meta.env?.DEV) { expectAssertion( () => this.render( diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js index 2bcb15b2171..be98a8b806d 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - import { RenderingTestCase, moduleFor, @@ -34,7 +32,7 @@ moduleFor( } ['@test it does not resolve helpers with a `.` (period)'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'nothing to do in prod builds, assertion is stripped'); return; } @@ -453,7 +451,7 @@ moduleFor( } ['@test simple helper not usable with a block'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -465,7 +463,7 @@ moduleFor( } ['@test class-based helper not usable with a block'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -480,7 +478,7 @@ moduleFor( } ['@test simple helper not usable within element'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -493,7 +491,7 @@ moduleFor( } ['@test class-based helper not usable within element'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -724,7 +722,7 @@ moduleFor( '@test Cannot dynamically resolve a helper'(assert) { this.registerHelper('hello-world', () => 'Hello, world!'); - if (DEBUG) { + if (import.meta.env?.DEV) { expectAssertion( () => this.render('{{helper this.name}}', { name: 'hello-world' }), /Passing a dynamic string to the `\(helper\)` keyword is disallowed\./ @@ -785,7 +783,7 @@ moduleFor( } ); -if (DEBUG) { +if (import.meta.env?.DEV) { class HelperMutatingArgsTests extends RenderingTestCase { buildCompute() { return (params, hash) => { diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js index 76565b18504..198b3ec220b 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/fn-test.js @@ -1,5 +1,5 @@ import { set } from '@ember/object'; -import { DEBUG } from '@glimmer/env'; + import { RenderingTestCase, defineComponent, moduleFor, runTask } from 'internal-test-helpers'; import { Component } from '../../utils/helpers'; @@ -128,7 +128,7 @@ moduleFor( } '@test there is no `this` context within the callback'(assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/helper-manager-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/helper-manager-test.js index c585cb9ef79..7279faa330a 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/helper-manager-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/helper-manager-test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { helperCapabilities, setHelperManager, setModifierManager } from '@glimmer/manager'; import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers'; import { tracked } from '@ember/-internals/metal'; @@ -239,7 +238,7 @@ moduleFor( } ['@test asserts against using both `hasValue` and `hasScheduledEffect`'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -253,7 +252,7 @@ moduleFor( } ['@test asserts requiring either `hasValue` or `hasScheduledEffect`'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -264,7 +263,7 @@ moduleFor( } ['@test asserts against using `hasScheduledEffect`'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -277,7 +276,7 @@ moduleFor( } ['@test asserts against using incorrect version for capabilities'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -311,7 +310,7 @@ moduleFor( } '@test capabilities helper function must be used to generate capabilities'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/invoke-helper-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/invoke-helper-test.js index 9c37e87b36e..4f50ce73b5b 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/invoke-helper-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/invoke-helper-test.js @@ -5,7 +5,7 @@ import { tracked } from '@ember/-internals/metal'; import { set } from '@ember/object'; import { getOwner } from '@ember/-internals/owner'; import Service, { service } from '@ember/service'; -import { DEBUG } from '@glimmer/env'; + import { getValue } from '@glimmer/validator'; import { destroy, isDestroyed, registerDestructor } from '@glimmer/destroyable'; import { invokeHelper } from '@glimmer/runtime'; @@ -414,7 +414,7 @@ moduleFor( } '@test throws an error if value is accessed after it is destroyed'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -434,7 +434,7 @@ moduleFor( } '@test asserts if no context object is passed'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } @@ -590,7 +590,7 @@ moduleFor( } '@test args are frozen in debug builds'(assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); } else { assert.expect(1); diff --git a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js index e7c25a768b9..3001d7f1dc3 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js @@ -2,8 +2,6 @@ import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; import { getInternalModifierManager } from '@glimmer/manager'; import { on } from '@glimmer/runtime'; -import { DEBUG } from '@glimmer/env'; - import { Component } from '../../utils/helpers'; moduleFor( @@ -246,7 +244,7 @@ moduleFor( } [`@test it throws a helpful error when callback is undefined`](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { let expectedMessage = /You must pass a function as the second argument to the `on` modifier/; assert.throws(() => { @@ -258,7 +256,7 @@ moduleFor( } [`@test it throws a helpful error when callback is null`](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { let expectedMessage = /You must pass a function as the second argument to the `on` modifier/; assert.throws(() => { diff --git a/packages/@ember/-internals/glimmer/tests/integration/mount-test.js b/packages/@ember/-internals/glimmer/tests/integration/mount-test.js index f48661b5db8..b85f2fff127 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/mount-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/mount-test.js @@ -7,7 +7,6 @@ import { runTask, } from 'internal-test-helpers'; -import { DEBUG } from '@glimmer/env'; import { set } from '@ember/object'; import { getOwner } from '@ember/-internals/owner'; import Controller from '@ember/controller'; @@ -116,7 +115,7 @@ moduleFor( } async ['@test it emits a useful backtracking re-render assertion message'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'nothing to do in prod builds, assertion is stripped'); return; } diff --git a/packages/@ember/-internals/meta/lib/meta.ts b/packages/@ember/-internals/meta/lib/meta.ts index 7d429b5f13e..a1cb6dd162e 100644 --- a/packages/@ember/-internals/meta/lib/meta.ts +++ b/packages/@ember/-internals/meta/lib/meta.ts @@ -2,7 +2,7 @@ import type { ComputedProperty } from '@ember/-internals/metal'; import { symbol, toString } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; import { isDestroyed } from '@glimmer/destroyable'; -import { DEBUG } from '@glimmer/env'; + import type { Revision, UpdatableTag } from '@glimmer/validator'; type ObjMap = { [key: string]: T }; @@ -31,7 +31,7 @@ export interface MetaCounters { } let counters: MetaCounters | undefined; -if (DEBUG) { +if (import.meta.env?.DEV) { counters = { peekCalls: 0, peekPrototypeWalks: 0, @@ -115,10 +115,10 @@ export class Meta { /** @internal */ _flattenedVersion = 0; - // DEBUG + // import.meta.env?.DEV /** @internal */ constructor(obj: object) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.metaInstantiated++; } this._parent = undefined; @@ -236,7 +236,7 @@ export class Meta { /** @internal */ writableLazyChainsFor(key: string): [UpdatableTag, unknown][] { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.writableLazyChainsCalls++; } @@ -253,7 +253,7 @@ export class Meta { /** @internal */ readableLazyChainsFor(key: string): [UpdatableTag, unknown][] | undefined { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.readableLazyChainsCalls++; } @@ -359,7 +359,7 @@ export class Meta { once: boolean, sync: boolean ) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.addToListenersCalls++; } @@ -368,7 +368,7 @@ export class Meta { /** @internal */ removeFromListeners(eventName: string, target: object | null, method: Function | string): void { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.removeFromListenersCalls++; } @@ -456,7 +456,7 @@ export class Meta { this._flattenedVersion === currentListenerVersion && (this.source === this.proto || this._inheritedEnd === -1) ) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.reopensAfterFlatten++; } @@ -487,12 +487,12 @@ export class Meta { be updated very often in practice. */ private flattenedListeners(): Listener[] | undefined { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.flattenedListenersCalls++; } if (this._flattenedVersion < currentListenerVersion) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.listenersFlattened++; } @@ -507,7 +507,7 @@ export class Meta { // If this instance doesn't have any of its own listeners (writableListeners // has never been called) then we don't need to do any flattening, return // the parent's listeners instead. - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.parentListenersUsed++; } @@ -529,7 +529,7 @@ export class Meta { ); if (index === -1) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.listenersInherited++; } @@ -552,7 +552,7 @@ export class Meta { let listeners = this.flattenedListeners(); let result; - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.matchingListenersCalls++; } @@ -583,7 +583,7 @@ export class Meta { let listeners = this.flattenedListeners(); let result; - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.observerEventsCalls++; } @@ -621,7 +621,7 @@ export function setMeta(obj: object, meta: Meta) { typeof obj === 'object' || typeof obj === 'function' ); - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.setCalls++; } metaStore.set(obj, meta); @@ -635,7 +635,7 @@ export function peekMeta(obj: object): Meta | null { typeof obj === 'object' || typeof obj === 'function' ); - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.peekCalls++; } @@ -648,7 +648,7 @@ export function peekMeta(obj: object): Meta | null { let pointer = getPrototypeOf(obj); while (pointer !== null) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.peekPrototypeWalks++; } @@ -699,7 +699,7 @@ export const meta: { typeof obj === 'object' || typeof obj === 'function' ); - if (DEBUG) { + if (import.meta.env?.DEV) { counters!.metaCalls++; } @@ -715,7 +715,7 @@ export const meta: { return newMeta; }; -if (DEBUG) { +if (import.meta.env?.DEV) { meta._counters = counters; } diff --git a/packages/@ember/-internals/meta/tests/listeners_test.js b/packages/@ember/-internals/meta/tests/listeners_test.js index ee59d3c0096..54f21857d1e 100644 --- a/packages/@ember/-internals/meta/tests/listeners_test.js +++ b/packages/@ember/-internals/meta/tests/listeners_test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { AbstractTestCase, moduleFor } from 'internal-test-helpers'; import { meta, counters } from '..'; @@ -77,7 +76,7 @@ moduleFor( } ['@test parent caching'](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters.flattenedListenersCalls = 0; counters.parentListenersUsed = 0; } @@ -92,21 +91,21 @@ moduleFor( let matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); - if (DEBUG) { + if (import.meta.env?.DEV) { assert.equal(counters.flattenedListenersCalls, 2); assert.equal(counters.parentListenersUsed, 1); } matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); - if (DEBUG) { + if (import.meta.env?.DEV) { assert.equal(counters.flattenedListenersCalls, 3); assert.equal(counters.parentListenersUsed, 1); } } ['@test parent cache invalidation'](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { counters.flattenedListenersCalls = 0; counters.parentListenersUsed = 0; counters.listenersInherited = 0; @@ -122,7 +121,7 @@ moduleFor( let matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); - if (DEBUG) { + if (import.meta.env?.DEV) { assert.equal(counters.flattenedListenersCalls, 2); assert.equal(counters.parentListenersUsed, 1); assert.equal(counters.listenersInherited, 0); @@ -133,7 +132,7 @@ moduleFor( matching = m.matchingListeners('hello'); assert.equal(matching.length, 6); - if (DEBUG) { + if (import.meta.env?.DEV) { assert.equal(counters.flattenedListenersCalls, 4); assert.equal(counters.parentListenersUsed, 1); assert.equal(counters.listenersInherited, 1); @@ -141,7 +140,7 @@ moduleFor( } ['@test reopen after flatten'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@ember/-internals/metal/lib/cached.ts b/packages/@ember/-internals/metal/lib/cached.ts index b40ccf4a2de..2951286f82a 100644 --- a/packages/@ember/-internals/metal/lib/cached.ts +++ b/packages/@ember/-internals/metal/lib/cached.ts @@ -1,7 +1,7 @@ // NOTE: copied from: https://github.com/glimmerjs/glimmer.js/pull/358 // Both glimmerjs/glimmer.js and emberjs/ember.js have the exact same implementation // of @cached, so any changes made to one should also be made to the other -import { DEBUG } from '@glimmer/env'; + import { createCache, getValue } from '@glimmer/validator'; /** @@ -97,9 +97,9 @@ export const cached: MethodDecorator = (...args: any[]) => { const [target, key, descriptor] = args; // Error on `@cached()`, `@cached(...args)`, and `@cached propName = value;` - if (DEBUG && target === undefined) throwCachedExtraneousParens(); + if (import.meta.env?.DEV && target === undefined) throwCachedExtraneousParens(); if ( - DEBUG && + import.meta.env?.DEV && (typeof target !== 'object' || typeof key !== 'string' || typeof descriptor !== 'object' || @@ -107,7 +107,7 @@ export const cached: MethodDecorator = (...args: any[]) => { ) { throwCachedInvalidArgsError(args); } - if (DEBUG && (!('get' in descriptor) || typeof descriptor.get !== 'function')) { + if (import.meta.env?.DEV && (!('get' in descriptor) || typeof descriptor.get !== 'function')) { throwCachedGetterOnlyError(key); } diff --git a/packages/@ember/-internals/metal/lib/computed.ts b/packages/@ember/-internals/metal/lib/computed.ts index aac84147b84..df68e6f0a41 100644 --- a/packages/@ember/-internals/metal/lib/computed.ts +++ b/packages/@ember/-internals/metal/lib/computed.ts @@ -3,7 +3,7 @@ import { meta as metaFor } from '@ember/-internals/meta'; import { toString } from '@ember/-internals/utils'; import { assert, inspect } from '@ember/debug'; import { isDestroyed } from '@glimmer/destroyable'; -import { DEBUG } from '@glimmer/env'; + import type { UpdatableTag } from '@glimmer/validator'; import { ALLOW_CYCLES, @@ -420,7 +420,7 @@ export class ComputedProperty extends ComputedDescriptor { if (_dependentKeys !== undefined) { updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta)); - if (DEBUG) { + if (import.meta.env?.DEV) { ALLOW_CYCLES!.set(propertyTag, true); } } @@ -498,7 +498,7 @@ export class ComputedProperty extends ComputedDescriptor { if (_dependentKeys !== undefined) { updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta)); - if (DEBUG) { + if (import.meta.env?.DEV) { ALLOW_CYCLES!.set(propertyTag, true); } } diff --git a/packages/@ember/-internals/metal/lib/decorator.ts b/packages/@ember/-internals/metal/lib/decorator.ts index 8e749b87a70..ef253a4c39b 100644 --- a/packages/@ember/-internals/metal/lib/decorator.ts +++ b/packages/@ember/-internals/metal/lib/decorator.ts @@ -1,7 +1,6 @@ import type { Meta } from '@ember/-internals/meta'; import { meta as metaFor, peekMeta } from '@ember/-internals/meta'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; export type DecoratorPropertyDescriptor = (PropertyDescriptor & { initializer?: any }) | undefined; @@ -78,7 +77,7 @@ export abstract class ComputedDescriptor { export let COMPUTED_GETTERS: WeakSet<() => unknown>; -if (DEBUG) { +if (import.meta.env?.DEV) { COMPUTED_GETTERS = new WeakSet(); } @@ -87,7 +86,7 @@ function DESCRIPTOR_GETTER_FUNCTION(name: string, descriptor: ComputedDescriptor return descriptor.get(this, name); } - if (DEBUG) { + if (import.meta.env?.DEV) { COMPUTED_GETTERS.add(getter); } @@ -125,7 +124,7 @@ export function makeComputedDecorator( isClassicDecorator || !propertyDesc || !propertyDesc.get || - !COMPUTED_GETTERS.has(propertyDesc.get) + !(import.meta.env?.DEV && COMPUTED_GETTERS.has(propertyDesc.get)) ); let meta = arguments.length === 3 ? metaFor(target) : maybeMeta; diff --git a/packages/@ember/-internals/metal/lib/injected_property.ts b/packages/@ember/-internals/metal/lib/injected_property.ts index 1228bf97454..e9a7ae2f9bc 100644 --- a/packages/@ember/-internals/metal/lib/injected_property.ts +++ b/packages/@ember/-internals/metal/lib/injected_property.ts @@ -1,6 +1,6 @@ import { getOwner } from '@ember/-internals/owner'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { computed } from './computed'; import type { DecoratorPropertyDescriptor, ElementDescriptor } from './decorator'; import { isElementDescriptor } from './decorator'; @@ -8,7 +8,7 @@ import { defineProperty } from './properties'; export let DEBUG_INJECTION_FUNCTIONS: WeakMap; -if (DEBUG) { +if (import.meta.env?.DEV) { DEBUG_INJECTION_FUNCTIONS = new WeakMap(); } @@ -66,7 +66,7 @@ function inject( return owner.lookup(`${type}:${name || propertyName}`); }; - if (DEBUG) { + if (import.meta.env?.DEV) { DEBUG_INJECTION_FUNCTIONS.set(getInjection, { type, name, diff --git a/packages/@ember/-internals/metal/lib/libraries.ts b/packages/@ember/-internals/metal/lib/libraries.ts index 6b474665950..09518a33234 100644 --- a/packages/@ember/-internals/metal/lib/libraries.ts +++ b/packages/@ember/-internals/metal/lib/libraries.ts @@ -1,5 +1,5 @@ import { assert, debug, warn } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import VERSION from 'ember/version'; import { get } from './property_get'; @@ -73,7 +73,7 @@ export class Libraries { declare logVersions?: () => void; } -if (DEBUG) { +if (import.meta.env?.DEV) { Libraries.prototype.logVersions = function (): void { let libs = this._registry; let nameLengths = libs.map((item) => get(item, 'name.length')); diff --git a/packages/@ember/-internals/metal/lib/properties.ts b/packages/@ember/-internals/metal/lib/properties.ts index 68ec802b1ef..986f2b63501 100644 --- a/packages/@ember/-internals/metal/lib/properties.ts +++ b/packages/@ember/-internals/metal/lib/properties.ts @@ -5,7 +5,7 @@ import type { Meta } from '@ember/-internals/meta'; import { meta as metaFor } from '@ember/-internals/meta'; import { setWithMandatorySetter } from '@ember/-internals/utils'; -import { DEBUG } from '@glimmer/env'; + import type { ExtendedMethodDecorator } from './decorator'; import { descriptorForProperty, isClassicDecorator } from './decorator'; import { revalidateObservers } from './observer'; @@ -97,7 +97,7 @@ export function defineDecorator( ) { let propertyDesc; - if (DEBUG) { + if (import.meta.env?.DEV) { propertyDesc = desc(obj, keyName, undefined, meta, true); } else { propertyDesc = desc(obj, keyName, undefined, meta); @@ -124,7 +124,7 @@ export function defineValue( value, }); } else { - if (DEBUG) { + if (import.meta.env?.DEV) { setWithMandatorySetter!(obj, keyName, value); } else { (obj as any)[keyName] = value; diff --git a/packages/@ember/-internals/metal/lib/property_get.ts b/packages/@ember/-internals/metal/lib/property_get.ts index ef86dd3b8d4..ce7849fea07 100644 --- a/packages/@ember/-internals/metal/lib/property_get.ts +++ b/packages/@ember/-internals/metal/lib/property_get.ts @@ -5,7 +5,7 @@ import type { _ProxyMixin as ProxyMixin } from '@ember/-internals/runtime'; import { setProxy, symbol } from '@ember/-internals/utils'; import { isEmberArray } from '@ember/array/-internals'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { consumeTag, isTracking, tagFor, track } from '@glimmer/validator'; import { isPath } from './path_cache'; @@ -13,7 +13,7 @@ export const PROXY_CONTENT = symbol('PROXY_CONTENT'); export let getPossibleMandatoryProxyValue: (obj: object, keyName: string) => any; -if (DEBUG) { +if (import.meta.env?.DEV) { getPossibleMandatoryProxyValue = function getPossibleMandatoryProxyValue(obj, keyName): any { let content = (obj as any)[PROXY_CONTENT]; if (content === undefined) { @@ -110,7 +110,7 @@ export function _getProp(obj: unknown, keyName: string) { let value: unknown; if (typeof obj === 'object' || typeof obj === 'function') { - if (DEBUG) { + if (import.meta.env?.DEV) { value = getPossibleMandatoryProxyValue(obj, keyName); } else { value = (obj as any)[keyName]; diff --git a/packages/@ember/-internals/metal/lib/property_set.ts b/packages/@ember/-internals/metal/lib/property_set.ts index 65b78f9c1ed..60cbda81b0f 100644 --- a/packages/@ember/-internals/metal/lib/property_set.ts +++ b/packages/@ember/-internals/metal/lib/property_set.ts @@ -1,6 +1,6 @@ import { lookupDescriptor, setWithMandatorySetter, toString } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { COMPUTED_SETTERS } from './decorator'; import { isPath } from './path_cache'; import { notifyPropertyChange } from './property_events'; @@ -74,7 +74,7 @@ export function _setProp(obj: object, keyName: string, value: any) { } let currentValue: any; - if (DEBUG) { + if (import.meta.env?.DEV) { currentValue = getPossibleMandatoryProxyValue(obj, keyName); } else { currentValue = (obj as any)[keyName]; @@ -89,7 +89,7 @@ export function _setProp(obj: object, keyName: string, value: any) { /* unknown property */ (obj as ExtendedObject).setUnknownProperty!(keyName, value); } else { - if (DEBUG) { + if (import.meta.env?.DEV) { setWithMandatorySetter!(obj, keyName, value); } else { (obj as any)[keyName] = value; diff --git a/packages/@ember/-internals/metal/lib/tags.ts b/packages/@ember/-internals/metal/lib/tags.ts index 47f028c63ce..7c5ce32b474 100644 --- a/packages/@ember/-internals/metal/lib/tags.ts +++ b/packages/@ember/-internals/metal/lib/tags.ts @@ -1,7 +1,7 @@ import { isObject, setupMandatorySetter, symbol, toString } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; import { isDestroyed } from '@glimmer/destroyable'; -import { DEBUG } from '@glimmer/env'; + import { getCustomTagFor } from '@glimmer/manager'; import type { Tag, TagMeta } from '@glimmer/validator'; import { CONSTANT_TAG, dirtyTagFor, tagFor } from '@glimmer/validator'; @@ -31,7 +31,7 @@ export function tagForProperty( let tag = tagFor(obj, propertyKey, meta); - if (DEBUG && addMandatorySetter) { + if (import.meta.env?.DEV && addMandatorySetter) { setupMandatorySetter!(tag, obj, propertyKey); } @@ -40,7 +40,7 @@ export function tagForProperty( export function tagForObject(obj: unknown | null): Tag { if (isObject(obj)) { - if (DEBUG) { + if (import.meta.env?.DEV) { assert( isDestroyed(obj) ? `Cannot create a new tag for \`${toString(obj)}\` after it has been destroyed.` diff --git a/packages/@ember/-internals/metal/lib/tracked.ts b/packages/@ember/-internals/metal/lib/tracked.ts index 226b632c2e3..f58378e9944 100644 --- a/packages/@ember/-internals/metal/lib/tracked.ts +++ b/packages/@ember/-internals/metal/lib/tracked.ts @@ -1,7 +1,7 @@ import { meta as metaFor } from '@ember/-internals/meta'; import { isEmberArray } from '@ember/array/-internals'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { consumeTag, dirtyTagFor, tagFor, trackedData } from '@glimmer/validator'; import type { ElementDescriptor } from '..'; import { CHAIN_PASS_THROUGH } from './chain-tags'; @@ -95,7 +95,7 @@ export function tracked(...args: any[]): ExtendedMethodDecorator | DecoratorProp args.length === 0 || (typeof propertyDesc === 'object' && propertyDesc !== null) ); - if (DEBUG && propertyDesc) { + if (import.meta.env?.DEV && propertyDesc) { let keys = Object.keys(propertyDesc); assert( @@ -140,7 +140,7 @@ export function tracked(...args: any[]): ExtendedMethodDecorator | DecoratorProp return descriptorForField(args); } -if (DEBUG) { +if (import.meta.env?.DEV) { // Normally this isn't a classic decorator, but we want to throw a helpful // error in development so we need it to treat it like one setClassicDecorator(tracked); diff --git a/packages/@ember/-internals/metal/tests/libraries_test.js b/packages/@ember/-internals/metal/tests/libraries_test.js index 169c0ad3b1c..139a2dbc45b 100644 --- a/packages/@ember/-internals/metal/tests/libraries_test.js +++ b/packages/@ember/-internals/metal/tests/libraries_test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { getDebugFunction, setDebugFunction } from '@ember/debug'; import { Libraries } from '..'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; @@ -46,7 +45,7 @@ moduleFor( } ['@test attempting to register a library that is already registered warns you'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Logging does not occur in production builds'); return; } diff --git a/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts b/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts index e7e3e218454..b5c7c3ba8a8 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts +++ b/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts @@ -14,7 +14,7 @@ import { } from '@ember/-internals/metal'; import { setProxy, setupMandatorySetter, isObject, isProxy } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { setCustomTagFor } from '@glimmer/manager'; import type { UpdatableTag, Tag } from '@glimmer/validator'; import { combine, updateTag, tagFor, tagMetaFor } from '@glimmer/validator'; @@ -34,15 +34,18 @@ function customTagForProxy(proxy: object, key: string, addMandatorySetter?: bool let meta = tagMetaFor(proxy); let tag = tagFor(proxy, key, meta); - if (DEBUG) { - // TODO: Replace this with something more first class for tracking tags in DEBUG + if (import.meta.env?.DEV) { + // TODO: Replace this with something more first class for tracking tags in import.meta.env?.DEV // SAFETY: This is not an officially supported property but setting shouldn't cause issues. (tag as any)._propertyKey = key; } if (key in proxy) { - if (DEBUG && addMandatorySetter) { - assert('[BUG] setupMandatorySetter should be set when debugging', setupMandatorySetter); + if (import.meta.env?.DEV && addMandatorySetter) { + assert( + '[BUG] setupMandatorySetter should be set when debugging', + setupMandatorySetter !== undefined + ); setupMandatorySetter(tag, proxy, key); } diff --git a/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts b/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts index f01223f2b42..9123340eaaf 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts +++ b/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts @@ -6,7 +6,6 @@ import { context } from '@ember/-internals/environment'; import { get, computed } from '@ember/-internals/metal'; import Mixin from '@ember/object/mixin'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; /** `TargetActionSupport` is a mixin that can be included in a class @@ -170,7 +169,7 @@ function getTarget(instance: TargetActionSupport) { return null; } -if (DEBUG) { +if (import.meta.env?.DEV) { Object.seal(TargetActionSupport); } diff --git a/packages/@ember/-internals/runtime/tests/inject_test.js b/packages/@ember/-internals/runtime/tests/inject_test.js index b054baf4518..a10edc3054a 100644 --- a/packages/@ember/-internals/runtime/tests/inject_test.js +++ b/packages/@ember/-internals/runtime/tests/inject_test.js @@ -1,5 +1,5 @@ import { inject } from '@ember/-internals/metal'; -import { DEBUG } from '@glimmer/env'; + import EmberObject from '@ember/object'; import { buildOwner } from 'internal-test-helpers'; import { runDestroy, moduleFor, AbstractTestCase } from 'internal-test-helpers'; @@ -24,7 +24,7 @@ moduleFor( } ['@test factories should return a list of lazy injection full names'](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { let AnObject = class extends EmberObject { @inject('foo', 'bar') foo; diff --git a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js b/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js index c5279308e64..bbae7fc67d5 100644 --- a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js +++ b/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { addObserver, removeObserver } from '@ember/-internals/metal'; import { computed, get, set, observer } from '@ember/object'; import ObjectProxy from '@ember/object/proxy'; @@ -98,7 +97,7 @@ moduleFor( } ['@test calling a function on the proxy avoids the assertion'](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { let proxy = class extends ObjectProxy { init() { super.init(); @@ -151,7 +150,7 @@ moduleFor( } ['@test getting proxied properties with [] should be an error'](assert) { - if (DEBUG) { + if (import.meta.env?.DEV) { let proxy = ObjectProxy.create({ content: { foo: 'FOO', diff --git a/packages/@ember/-internals/utils/lib/get-debug-name.ts b/packages/@ember/-internals/utils/lib/get-debug-name.ts index 620055cf360..d564659f66f 100644 --- a/packages/@ember/-internals/utils/lib/get-debug-name.ts +++ b/packages/@ember/-internals/utils/lib/get-debug-name.ts @@ -1,8 +1,6 @@ -import { DEBUG } from '@glimmer/env'; - let getDebugName: undefined | ((value: any) => string); -if (DEBUG) { +if (import.meta.env?.DEV) { let getFunctionName = (fn: Function) => { let functionName = fn.name; diff --git a/packages/@ember/-internals/utils/lib/mandatory-setter.ts b/packages/@ember/-internals/utils/lib/mandatory-setter.ts index 92e157f8d8e..ef04f692b49 100644 --- a/packages/@ember/-internals/utils/lib/mandatory-setter.ts +++ b/packages/@ember/-internals/utils/lib/mandatory-setter.ts @@ -1,5 +1,5 @@ import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import type { Tag } from '@glimmer/validator'; import lookupDescriptor from './lookup-descriptor'; @@ -24,7 +24,7 @@ function isPositiveInt(num: number) { return num >= 0 && num % 1 === 0; } -if (DEBUG) { +if (import.meta.env?.DEV) { let SEEN_TAGS = new WeakSet(); let MANDATORY_SETTERS: WeakMap = diff --git a/packages/@ember/-internals/utils/lib/symbol.ts b/packages/@ember/-internals/utils/lib/symbol.ts index b4f4318f754..6c7f07cb1b8 100644 --- a/packages/@ember/-internals/utils/lib/symbol.ts +++ b/packages/@ember/-internals/utils/lib/symbol.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { GUID_KEY } from './guid'; import intern from './intern'; @@ -18,7 +17,7 @@ export function enumerableSymbol(debugName: string): string { let id = GUID_KEY + Math.floor(Math.random() * Date.now()).toString(); let symbol = intern(`__${debugName}${id}__`); - if (DEBUG) { + if (import.meta.env?.DEV) { GENERATED_SYMBOLS.push(symbol); } diff --git a/packages/@ember/-internals/utils/tests/get-debug-name-test.js b/packages/@ember/-internals/utils/tests/get-debug-name-test.js index ffd0ee6d731..7430a944b6b 100644 --- a/packages/@ember/-internals/utils/tests/get-debug-name-test.js +++ b/packages/@ember/-internals/utils/tests/get-debug-name-test.js @@ -1,8 +1,7 @@ import { getDebugName } from '..'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -import { DEBUG } from '@glimmer/env'; -if (DEBUG) { +if (import.meta.env?.DEV) { moduleFor( '@ember/-internals/utils getDebugName', class extends AbstractTestCase { diff --git a/packages/@ember/-internals/views/lib/views/states.ts b/packages/@ember/-internals/views/lib/views/states.ts index c9480ffbdf4..14f6f608b9d 100644 --- a/packages/@ember/-internals/views/lib/views/states.ts +++ b/packages/@ember/-internals/views/lib/views/states.ts @@ -3,7 +3,6 @@ import type Component from '@ember/component'; import { assert } from '@ember/debug'; import { flaggedInstrument } from '@ember/instrumentation'; import { join } from '@ember/runloop'; -import { DEBUG } from '@glimmer/env'; export interface ViewState { enter?(view: Component): void; @@ -65,12 +64,12 @@ const IN_DOM: Readonly = Object.freeze({ // Ember.EventDispatcher to dispatch incoming events. view.renderer.register(view); - if (DEBUG) { + if (import.meta.env?.DEV) { let elementId = view.elementId; assert( - '[BUG] Expected teardownMandatorySetter to be set in DEBUG mode', - teardownMandatorySetter + '[BUG] Expected teardownMandatorySetter to be set in DEV mode', + teardownMandatorySetter !== undefined ); teardownMandatorySetter(view, 'elementId'); diff --git a/packages/@ember/application/index.ts b/packages/@ember/application/index.ts index 5f3231bbd29..f0d24f3654a 100644 --- a/packages/@ember/application/index.ts +++ b/packages/@ember/application/index.ts @@ -7,7 +7,7 @@ import { dictionary } from '@ember/-internals/utils'; import { ENV } from '@ember/-internals/environment'; import { hasDOM } from '@ember/-internals/browser-environment'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { join, once, run, schedule } from '@ember/runloop'; import { libraries } from '@ember/-internals/metal'; import { _loaded, onLoad, runLoadHooks } from './lib/lazy_load'; @@ -415,7 +415,7 @@ class Application extends Engine { this._document ??= hasDOM ? window.document : null; this._globalsMode ??= true; - if (DEBUG) { + if (import.meta.env?.DEV) { if (ENV.LOG_VERSION) { // we only need to see this once per Application#init ENV.LOG_VERSION = false; diff --git a/packages/@ember/application/tests/application_test.js b/packages/@ember/application/tests/application_test.js index 89c708caab1..0c54dda0ce6 100644 --- a/packages/@ember/application/tests/application_test.js +++ b/packages/@ember/application/tests/application_test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import VERSION from 'ember/version'; import { ENV } from '@ember/-internals/environment'; import { libraries } from '@ember/-internals/metal'; @@ -251,7 +250,7 @@ moduleFor( } [`@test enable log of libraries with an ENV var`](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Logging does not occur in production builds'); return; } diff --git a/packages/@ember/application/tests/logging_test.js b/packages/@ember/application/tests/logging_test.js index b7896989f48..4ba47a4b63f 100644 --- a/packages/@ember/application/tests/logging_test.js +++ b/packages/@ember/application/tests/logging_test.js @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; import Controller from '@ember/controller'; @@ -45,7 +43,7 @@ moduleFor( } ['@test log class generation if logging enabled'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Logging does not occur in production builds'); return; } @@ -56,7 +54,7 @@ moduleFor( } ['@test actively generated classes get logged'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Logging does not occur in production builds'); return; } @@ -124,7 +122,7 @@ moduleFor( } [`@test log when template and view are missing when flag is active`](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Logging does not occur in production builds'); return; } diff --git a/packages/@ember/array/index.ts b/packages/@ember/array/index.ts index e74008883f5..9ae5c46ed3b 100644 --- a/packages/@ember/array/index.ts +++ b/packages/@ember/array/index.ts @@ -1,7 +1,7 @@ /** @module @ember/array */ -import { DEBUG } from '@glimmer/env'; + import { PROXY_CONTENT } from '@ember/-internals/metal'; import { objectAt, @@ -165,7 +165,7 @@ function insertAt(array: MutableArray, index: number, item: T) { @public */ export function isArray(obj: unknown): obj is ArrayLike | EmberArray { - if (DEBUG && typeof obj === 'object' && obj !== null) { + if (import.meta.env?.DEV && typeof obj === 'object' && obj !== null) { // SAFETY: Property read checks are safe if it's an object let possibleProxyContent = (obj as any)[PROXY_CONTENT]; if (possibleProxyContent !== undefined) { diff --git a/packages/@ember/debug/index.ts b/packages/@ember/debug/index.ts index a466026cccc..c4f69bba455 100644 --- a/packages/@ember/debug/index.ts +++ b/packages/@ember/debug/index.ts @@ -1,6 +1,6 @@ import { isChrome, isFirefox } from '@ember/-internals/browser-environment'; import type { AnyFn } from '@ember/-internals/utility-types'; -import { DEBUG } from '@glimmer/env'; + import type { DeprecateFunc, DeprecationOptions } from './lib/deprecate'; import defaultDeprecate from './lib/deprecate'; import { isTesting } from './lib/testing'; @@ -86,7 +86,7 @@ export function deprecate(...args: Parameters): ReturnType ''; let deprecate: DeprecateFunc = () => {}; -if (DEBUG) { +if (import.meta.env?.DEV) { registerHandler = function registerHandler(handler: HandlerCallback): void { genericRegisterHandler('deprecate', handler); }; diff --git a/packages/@ember/debug/lib/handlers.ts b/packages/@ember/debug/lib/handlers.ts index a7df6c3979a..a17c0f832d0 100644 --- a/packages/@ember/debug/lib/handlers.ts +++ b/packages/@ember/debug/lib/handlers.ts @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - export type Options = object; export type Handler = (message: string, options?: O) => void; export type HandlerCallback = ( @@ -26,7 +24,7 @@ let registerHandler = function registerHandler( ) {}; let invoke: InvokeFunc = () => {}; -if (DEBUG) { +if (import.meta.env?.DEV) { registerHandler = function registerHandler( type: string, callback: HandlerCallback diff --git a/packages/@ember/debug/lib/warn.ts b/packages/@ember/debug/lib/warn.ts index 0a048571270..b8e63e21f57 100644 --- a/packages/@ember/debug/lib/warn.ts +++ b/packages/@ember/debug/lib/warn.ts @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - import { assert } from './assert'; import type { HandlerCallback } from './handlers'; import { invoke, registerHandler as genericRegisterHandler } from './handlers'; @@ -25,7 +23,7 @@ let missingOptionsIdDeprecation: string; @module @ember/debug */ -if (DEBUG) { +if (import.meta.env?.DEV) { /** Allows for runtime registration of handler functions that override the default warning behavior. Warnings are invoked by calls made to [@ember/debug/warn](/ember/release/classes/@ember%2Fdebug/methods/warn?anchor=warn). diff --git a/packages/@ember/object/-internals.ts b/packages/@ember/object/-internals.ts index f59d4196604..a3bbdcf359b 100644 --- a/packages/@ember/object/-internals.ts +++ b/packages/@ember/object/-internals.ts @@ -4,7 +4,7 @@ export { guidFor } from '@ember/-internals/utils'; import { addListener } from '@ember/-internals/metal'; import { assert } from '@ember/debug'; import { symbol } from '@ember/-internals/utils'; -import { DEBUG } from '@glimmer/env'; + import EmberObject from '.'; // Here we have runtime shenanigans to add debug-only errors to the class in dev @@ -25,7 +25,7 @@ import EmberObject from '.'; interface FrameworkObject extends EmberObject {} let FrameworkObject: typeof EmberObject = class FrameworkObject extends EmberObject {}; -if (DEBUG) { +if (import.meta.env?.DEV) { const INIT_WAS_CALLED = Symbol('INIT_WAS_CALLED'); let ASSERT_INIT_WAS_CALLED = symbol('ASSERT_INIT_WAS_CALLED'); diff --git a/packages/@ember/object/core.ts b/packages/@ember/object/core.ts index 106169e3ef8..e9a2577d50f 100644 --- a/packages/@ember/object/core.ts +++ b/packages/@ember/object/core.ts @@ -21,7 +21,7 @@ import Mixin, { applyMixin } from '@ember/object/mixin'; import { ActionHandler } from '@ember/-internals/runtime'; import makeArray from '@ember/array/make'; import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import { destroy, isDestroying, isDestroyed, registerDestructor } from '@glimmer/destroyable'; import { OWNER } from '@glimmer/owner'; @@ -59,7 +59,7 @@ const reopen = Mixin.prototype.reopen; const wasApplied = new WeakSet(); const prototypeMixinMap = new WeakMap(); -const initCalled = DEBUG ? new WeakSet() : undefined; // only used in debug builds to enable the proxy trap +const initCalled = import.meta.env?.DEV ? new WeakSet() : undefined; // only used in debug builds to enable the proxy trap const destroyCalled = new Set(); @@ -143,7 +143,7 @@ function initialize(obj: CoreObject, properties?: unknown) { } else if (hasSetUnknownProperty(obj) && !(keyName in obj)) { obj.setUnknownProperty(keyName, value); } else { - if (DEBUG) { + if (import.meta.env?.DEV) { defineProperty(obj, keyName, null, value, m); // setup mandatory setter } else { (obj as any)[keyName] = value; @@ -152,8 +152,8 @@ function initialize(obj: CoreObject, properties?: unknown) { } } - // using DEBUG here to avoid the extraneous variable when not needed - if (DEBUG) { + // using import.meta.env?.DEV here to avoid the extraneous variable when not needed + if (import.meta.env?.DEV) { initCalled!.add(obj); } obj.init(properties); @@ -247,7 +247,7 @@ class CoreObject { (this.constructor as typeof CoreObject).proto(); let self; - if (DEBUG && hasUnknownProperty(this)) { + if (import.meta.env?.DEV && hasUnknownProperty(this)) { let messageFor = (obj: unknown, property: unknown) => { return ( `You attempted to access the \`${String(property)}\` property (of ${obj}).\n` + @@ -308,7 +308,7 @@ class CoreObject { m.setInitializing(); // only return when in debug builds and `self` is the proxy created above - if (DEBUG && self !== this) { + if (import.meta.env?.DEV && self !== this) { return self; } } @@ -1080,7 +1080,7 @@ function flattenProps(this: typeof CoreObject, ...props: Array ${fullName}`, { fullName }); } diff --git a/packages/@ember/routing/route.ts b/packages/@ember/routing/route.ts index 7b4a8f24eac..d889ab62ab1 100644 --- a/packages/@ember/routing/route.ts +++ b/packages/@ember/routing/route.ts @@ -21,7 +21,7 @@ import { assert, info, isTesting } from '@ember/debug'; import EngineInstance from '@ember/engine/instance'; import { dependentKeyCompat } from '@ember/object/compat'; import { once } from '@ember/runloop'; -import { DEBUG } from '@glimmer/env'; + import { hasInternalComponentManager } from '@glimmer/manager'; import type { RenderState } from '@ember/-internals/glimmer'; import type { TemplateFactory } from '@glimmer/interfaces'; @@ -1827,7 +1827,7 @@ function buildRenderState(route: Route): RenderState { if (hasInternalComponentManager(templateFactoryOrComponent)) { template = templateFactoryOrComponent; } else { - if (DEBUG && typeof templateFactoryOrComponent !== 'function') { + if (import.meta.env?.DEV && typeof templateFactoryOrComponent !== 'function') { let label: string; try { @@ -1859,7 +1859,7 @@ function buildRenderState(route: Route): RenderState { template, }; - if (DEBUG) { + if (import.meta.env?.DEV) { let LOG_VIEW_LOOKUPS = get(route._router, 'namespace.LOG_VIEW_LOOKUPS'); // This is covered by tests and the existing code was deliberately // targeting the value prior to normalization, but is this message actually diff --git a/packages/@ember/routing/router.ts b/packages/@ember/routing/router.ts index 114c398476e..6e4cfd3f19c 100644 --- a/packages/@ember/routing/router.ts +++ b/packages/@ember/routing/router.ts @@ -25,7 +25,7 @@ import { typeOf } from '@ember/utils'; import Evented from '@ember/object/evented'; import { assert, info } from '@ember/debug'; import { cancel, once, run, scheduleOnce } from '@ember/runloop'; -import { DEBUG } from '@glimmer/env'; + import { type QueryParamMeta, type default as Route, @@ -63,7 +63,7 @@ function defaultDidTransition(this: EmberRouter, infos: InternalRouteInfo this.notifyPropertyChange('url'); this.set('currentState', this.targetState); - if (DEBUG) { + if (import.meta.env?.DEV) { // @ts-expect-error namespace isn't public if (this.namespace.LOG_TRANSITIONS) { // eslint-disable-next-line no-console @@ -77,7 +77,7 @@ function defaultWillTransition( oldInfos: InternalRouteInfo[], newInfos: InternalRouteInfo[] ) { - if (DEBUG) { + if (import.meta.env?.DEV) { // @ts-expect-error namespace isn't public if (this.namespace.LOG_TRANSITIONS) { // eslint-disable-next-line no-console @@ -91,7 +91,7 @@ function defaultWillTransition( } let freezeRouteInfo: Function; -if (DEBUG) { +if (import.meta.env?.DEV) { freezeRouteInfo = (transition: Transition) => { if (transition.from !== null && !Object.isFrozen(transition.from)) { Object.freeze(transition.from); @@ -351,7 +351,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { routeOwner.register(fullRouteName, class extends DefaultRoute {}); route = routeOwner.lookup(fullRouteName) as Route; - if (DEBUG) { + if (import.meta.env?.DEV) { if (router.namespace.LOG_ACTIVE_GENERATION) { info(`generated -> ${fullRouteName}`, { fullName: fullRouteName }); } @@ -417,7 +417,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { routeWillChange(transition: Transition) { router.trigger('routeWillChange', transition); - if (DEBUG) { + if (import.meta.env?.DEV) { freezeRouteInfo(transition); } router._routerService.trigger('routeWillChange', transition); @@ -435,7 +435,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { once(() => { router.trigger('routeDidChange', transition); - if (DEBUG) { + if (import.meta.env?.DEV) { freezeRouteInfo(transition); } router._routerService.trigger('routeDidChange', transition); @@ -495,7 +495,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { } ); - if (DEBUG) { + if (import.meta.env?.DEV) { if (this.namespace.LOG_TRANSITIONS_INTERNAL) { routerMicrolib.log = console.log.bind(console); // eslint-disable-line no-console } @@ -726,7 +726,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { updatePaths(this); - if (DEBUG) { + if (import.meta.env?.DEV) { let infos = this._routerMicrolib.currentRouteInfos; if (this.namespace.LOG_TRANSITIONS) { assert('expected infos to be set', infos); @@ -1151,7 +1151,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { let shouldCache = true; let map: QueryParamMeta['map'] = {}; let qps = []; - let qpsByUrlKey: Record | null = DEBUG ? {} : null; + let qpsByUrlKey: Record | null = import.meta.env?.DEV ? {} : null; let qpMeta; let urlKey; let qpOther; @@ -1166,7 +1166,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { // Loop over each QP to make sure we don't have any collisions by urlKey for (let qp of qpMeta.qps) { - if (DEBUG) { + if (import.meta.env?.DEV) { urlKey = qp.urlKey; qpOther = qpsByUrlKey![urlKey]; if (qpOther && qpOther.controllerName !== qp.controllerName) { diff --git a/packages/@ember/template-compilation/index.ts b/packages/@ember/template-compilation/index.ts index 3f14172db73..3bd8d562362 100644 --- a/packages/@ember/template-compilation/index.ts +++ b/packages/@ember/template-compilation/index.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { TemplateFactory } from '@glimmer/interfaces'; import type * as ETC from 'ember-template-compiler'; @@ -31,7 +30,7 @@ export const compileTemplate: typeof ETC.compile = (...args: Parameters { throw new Error( 'Attempted to call `precompileTemplate` at runtime, but this API is meant to be used at compile time. You should use `compileTemplate` instead.' diff --git a/packages/@ember/template-compiler/lib/plugins/transform-resolutions.ts b/packages/@ember/template-compiler/lib/plugins/transform-resolutions.ts index 311a485d0e0..dc1afc5aff0 100644 --- a/packages/@ember/template-compiler/lib/plugins/transform-resolutions.ts +++ b/packages/@ember/template-compiler/lib/plugins/transform-resolutions.ts @@ -1,5 +1,5 @@ import { assert } from '@ember/debug'; -import { DEBUG } from '@glimmer/env'; + import type { AST, ASTPlugin } from '@glimmer/syntax'; import { print } from '@glimmer/syntax'; import calculateLocationDisplay from '../system/calculate-location-display'; @@ -179,7 +179,7 @@ function transformParams( ), ...rest, ]; - } else if (DEBUG) { + } else if (import.meta.env?.DEV) { return [ b.sexpr( b.path('-disallow-dynamic-resolution', first.loc), diff --git a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts index 71ced2a1246..ba5a9c0a2dc 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts @@ -7,7 +7,6 @@ import { RenderTest } from '../render-test'; import { test } from '../test-decorator'; import { strip, stripTight } from '../test-helpers/strings'; import { tracked } from '../test-helpers/tracked'; -import { DEBUG } from '@glimmer/env'; export class TemplateOnlyComponents extends RenderTest { static suiteName = 'TemplateOnly'; @@ -394,7 +393,7 @@ export class GlimmerishComponents extends RenderTest { @test({ kind: 'glimmer', - skip: !DEBUG, + skip: !import.meta.env?.DEV, }) 'invoking dynamic component (path) via angle brackets does not work for string'() { this.registerComponent('Glimmer', 'TestHarness', ''); @@ -770,7 +769,7 @@ export class GlimmerishComponents extends RenderTest { this.assertHTML('123'); } - @test({ kind: 'templateOnly', skip: !DEBUG }) + @test({ kind: 'templateOnly', skip: !import.meta.env?.DEV }) 'throwing an error during component construction does not put result into a bad state'() { this.registerComponent( 'Glimmer', @@ -798,7 +797,7 @@ export class GlimmerishComponents extends RenderTest { this.assertHTML('', 'destroys correctly'); } - @test({ kind: 'templateOnly', skip: !DEBUG }) + @test({ kind: 'templateOnly', skip: !import.meta.env?.DEV }) 'throwing an error during component construction does not put result into a bad state with multiple prior nodes'() { this.registerComponent( 'Glimmer', @@ -832,7 +831,7 @@ export class GlimmerishComponents extends RenderTest { this.assertHTML('', 'destroys correctly'); } - @test({ kind: 'templateOnly', skip: !DEBUG }) + @test({ kind: 'templateOnly', skip: !import.meta.env?.DEV }) 'throwing an error during component construction does not put result into a bad state with nested components'() { this.registerComponent( 'Glimmer', @@ -865,7 +864,7 @@ export class GlimmerishComponents extends RenderTest { this.assertHTML('', 'destroys correctly'); } - @test({ kind: 'templateOnly', skip: !DEBUG }) + @test({ kind: 'templateOnly', skip: !import.meta.env?.DEV }) 'throwing an error during rendering gives a readable error stack'(assert: Assert) { // eslint-disable-next-line no-console let originalConsoleError = console.error; diff --git a/packages/@glimmer-workspace/integration-tests/test/env-test.ts b/packages/@glimmer-workspace/integration-tests/test/env-test.ts index 674843170d8..e60e4cd2949 100644 --- a/packages/@glimmer-workspace/integration-tests/test/env-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/env-test.ts @@ -1,10 +1,10 @@ import { castToSimple } from '@glimmer/debug-util'; -import { DEBUG } from '@glimmer/env'; + import { EnvironmentImpl } from '@glimmer/runtime'; QUnit.module('[integration] env'); -if (DEBUG) { +if (import.meta.env?.DEV) { QUnit.test('assert against nested transactions', (assert) => { let env = new EnvironmentImpl( { document: castToSimple(document) }, diff --git a/packages/@glimmer-workspace/integration-tests/test/helpers/fn-test.ts b/packages/@glimmer-workspace/integration-tests/test/helpers/fn-test.ts index e3ae8ebded6..1e0e9a72ed3 100644 --- a/packages/@glimmer-workspace/integration-tests/test/helpers/fn-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/helpers/fn-test.ts @@ -6,7 +6,6 @@ import { RenderTest, test, } from '@glimmer-workspace/integration-tests'; -import { DEBUG } from '@glimmer/env'; class FnTest extends RenderTest { static suiteName = 'Helpers test: {{fn}}'; @@ -126,7 +125,7 @@ class FnTest extends RenderTest { assert.strictEqual(this.stashedFn?.(), 'arg1: foo, arg2: bar'); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if no argument given'(assert: Assert) { assert.throws(() => { this.render(`{{fn}}`, { @@ -137,7 +136,7 @@ class FnTest extends RenderTest { }, /You must pass a function as the `fn` helper's first argument./u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if the first argument is undefined'(assert: Assert) { assert.throws(() => { this.render(`{{fn this.myFunc this.arg1 this.arg2}}`, { @@ -148,7 +147,7 @@ class FnTest extends RenderTest { }, /You must pass a function as the `fn` helper's first argument, you passed undefined. While rendering:\n{2}this.myFunc/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if the first argument is null'(assert: Assert) { assert.throws(() => { this.render(`{{fn this.myFunc this.arg1 this.arg2}}`, { @@ -159,7 +158,7 @@ class FnTest extends RenderTest { }, /You must pass a function as the `fn` helper's first argument, you passed null. While rendering:\n{2}this.myFunc/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if the provided function accesses `this` without being bound prior to passing to fn'( assert: Assert ) { @@ -177,7 +176,7 @@ class FnTest extends RenderTest { }, /You accessed `this.arg2` from a function passed to the `fn` helper, but the function itself was not bound to a valid `this` context. Consider updating to use a bound function./u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'there is no `this` context within the callback'(assert: Assert) { this.render(``, { myFunc() { diff --git a/packages/@glimmer-workspace/integration-tests/test/managers/helper-manager-test.ts b/packages/@glimmer-workspace/integration-tests/test/managers/helper-manager-test.ts index 839d7295024..be3117c101d 100644 --- a/packages/@glimmer-workspace/integration-tests/test/managers/helper-manager-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/managers/helper-manager-test.ts @@ -13,7 +13,6 @@ import { trackedObj, } from '@glimmer-workspace/integration-tests'; import { consume } from '@glimmer-workspace/test-utils'; -import { DEBUG } from '@glimmer/env'; class HelperManagerTest extends RenderTest { static suiteName = 'Helper Managers'; @@ -352,7 +351,9 @@ class HelperManagerTest extends RenderTest { this.assertHTML('hello'); } - @test({ skip: !DEBUG }) 'debug name is used for backtracking message'(assert: Assert) { + @test({ skip: !import.meta.env?.DEV }) 'debug name is used for backtracking message'( + assert: Assert + ) { class Hello extends TestHelper { @tracked foo = 123; @@ -367,9 +368,8 @@ class HelperManagerTest extends RenderTest { }, /You attempted to update `foo` on/u); } - @test({ skip: !DEBUG }) 'asserts against using both `hasValue` and `hasScheduledEffect`'( - assert: Assert - ) { + @test({ skip: !import.meta.env?.DEV }) + 'asserts against using both `hasValue` and `hasScheduledEffect`'(assert: Assert) { assert.throws(() => { helperCapabilities('3.23', { hasValue: true, @@ -378,15 +378,16 @@ class HelperManagerTest extends RenderTest { }, /You must pass either the `hasValue` OR the `hasScheduledEffect` capability when defining a helper manager. Passing neither, or both, is not permitted./u); } - @test({ skip: !DEBUG }) 'asserts requiring either `hasValue` or `hasScheduledEffect`'( - assert: Assert - ) { + @test({ skip: !import.meta.env?.DEV }) + 'asserts requiring either `hasValue` or `hasScheduledEffect`'(assert: Assert) { assert.throws(() => { helperCapabilities('3.23', {}); }, /You must pass either the `hasValue` OR the `hasScheduledEffect` capability when defining a helper manager. Passing neither, or both, is not permitted./u); } - @test({ skip: !DEBUG }) 'asserts against using `hasScheduledEffect`'(assert: Assert) { + @test({ skip: !import.meta.env?.DEV }) 'asserts against using `hasScheduledEffect`'( + assert: Assert + ) { assert.throws(() => { helperCapabilities('3.23', { hasScheduledEffect: true, @@ -394,7 +395,7 @@ class HelperManagerTest extends RenderTest { }, /The `hasScheduledEffect` capability has not yet been implemented for helper managers. Please pass `hasValue` instead/u); } - @test({ skip: !DEBUG }) 'asserts against using incorrect version for capabilities'( + @test({ skip: !import.meta.env?.DEV }) 'asserts against using incorrect version for capabilities'( assert: Assert ) { assert.throws(() => { @@ -424,9 +425,8 @@ class HelperManagerTest extends RenderTest { this.assertHTML('hello'); } - @test({ skip: !DEBUG }) 'capabilities helper function must be used to generate capabilities'( - assert: Assert - ) { + @test({ skip: !import.meta.env?.DEV }) + 'capabilities helper function must be used to generate capabilities'(assert: Assert) { class OverrideTestHelperManager extends TestHelperManager { override capabilities = { hasValue: true, @@ -450,7 +450,7 @@ class HelperManagerTest extends RenderTest { }, /Custom helper managers must have a `capabilities` property that is the result of calling the `capabilities\('3.23'\)` \(imported via `import \{ capabilities \} from '@ember\/helper';`\). /u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'custom helpers gives helpful assertion when reading then mutating a tracked value within constructor'( assert: Assert ) { @@ -478,7 +478,7 @@ class HelperManagerTest extends RenderTest { }, /You attempted to update `foo` on /u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'custom helpers gives helpful assertion when reading then mutating a tracked value within value'( assert: Assert ) { diff --git a/packages/@glimmer-workspace/integration-tests/test/managers/modifier-manager-test.ts b/packages/@glimmer-workspace/integration-tests/test/managers/modifier-manager-test.ts index dd93d05ed05..f2b3a2d48d8 100644 --- a/packages/@glimmer-workspace/integration-tests/test/managers/modifier-manager-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/managers/modifier-manager-test.ts @@ -10,7 +10,6 @@ import { trackedObj, } from '@glimmer-workspace/integration-tests'; import { consume } from '@glimmer-workspace/test-utils'; -import { DEBUG } from '@glimmer/env'; abstract class CustomModifier { static create( @@ -216,7 +215,7 @@ abstract class ModifierManagerTest extends RenderTest { assert.strictEqual(updateCount, 2); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'provides a helpful deprecation when mutating a tracked value that was consumed already within constructor'( assert: Assert ) { diff --git a/packages/@glimmer-workspace/integration-tests/test/modifiers/on-test.ts b/packages/@glimmer-workspace/integration-tests/test/modifiers/on-test.ts index e67965b6027..e73b6b638cf 100644 --- a/packages/@glimmer-workspace/integration-tests/test/modifiers/on-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/modifiers/on-test.ts @@ -3,7 +3,6 @@ import { getInternalModifierManager } from '@glimmer/manager'; import { on } from '@glimmer/runtime'; import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests'; import { consume } from '@glimmer-workspace/test-utils'; -import { DEBUG } from '@glimmer/env'; // check if window exists and actually is the global const hasDom = @@ -208,7 +207,7 @@ if (hasDom) { this.assertCounts({ adds: 2, removes: 1 }); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'setting passive named argument prevents calling preventDefault'(assert: Assert) { let matcher = /You marked this listener as 'passive', meaning that you must not call 'event.preventDefault\(\)'/u; @@ -318,7 +317,7 @@ if (hasDom) { this.assertCounts({ adds: 1, removes: 0 }); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when eventName is missing'(assert: Assert) { assert.throws(() => { this.render(``, { @@ -327,7 +326,7 @@ if (hasDom) { }, /You must pass a valid DOM event name as the first argument to the `on` modifier/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when eventName is a bound undefined value'(assert: Assert) { assert.throws(() => { this.render(``, { @@ -336,7 +335,7 @@ if (hasDom) { }, /You must pass a valid DOM event name as the first argument to the `on` modifier/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when eventName is a function'(assert: Assert) { assert.throws(() => { this.render(``, { @@ -345,28 +344,28 @@ if (hasDom) { }, /You must pass a valid DOM event name as the first argument to the `on` modifier/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when callback is missing'(assert: Assert) { assert.throws(() => { this.render(``); }, /You must pass a function as the second argument to the `on` modifier/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when callback is undefined'(assert: Assert) { assert.throws(() => { this.render(``); }, /You must pass a function as the second argument to the `on` modifier; you passed undefined. While rendering:\n{2}this.foo/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts when callback is null'(assert: Assert) { assert.throws(() => { this.render(``, { foo: null }); }, /You must pass a function as the second argument to the `on` modifier; you passed null. While rendering:\n{2}this.foo/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if the provided callback accesses `this` without being bound prior to passing to on'( assert: Assert ) { @@ -383,7 +382,7 @@ if (hasDom) { this.findButton().click(); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'asserts if more than 2 positional parameters are provided'(assert: Assert) { assert.throws(() => { this.render(``, { diff --git a/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts b/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts index f00d6096ea1..594d201d8a3 100644 --- a/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts @@ -12,7 +12,6 @@ import { TestHelper, trackedObj, } from '@glimmer-workspace/integration-tests'; -import { DEBUG } from '@glimmer/env'; class GeneralStrictModeTest extends RenderTest { static suiteName = 'strict mode: general properties'; @@ -124,7 +123,7 @@ class GeneralStrictModeTest extends RenderTest { }, /\(component\) cannot resolve string values in strict mode templates/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict (append position)'() { const Foo = defineComponent({}, '{{component this.bar}}', { definition: class extends GlimmerishComponent { @@ -146,7 +145,7 @@ class GeneralStrictModeTest extends RenderTest { }, /The `component` keyword was used incorrectly. It was used as `component.foo`, but it cannot be used with additional path segments./u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict after first render (append position)'() { const Bar = defineComponent({}, 'Hello, world!'); @@ -172,7 +171,7 @@ class GeneralStrictModeTest extends RenderTest { }, /\(component\) cannot resolve string values in strict mode templates/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict (block position)'() { const Foo = defineComponent({}, '{{#component this.bar}}{{/component}}', { definition: class extends GlimmerishComponent { @@ -185,7 +184,7 @@ class GeneralStrictModeTest extends RenderTest { }, /Error: Attempted to resolve a dynamic component with a string definition, `bar` in a strict mode template. In strict mode, using strings to resolve component definitions is prohibited. You can instead import the component definition and use it directly./u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict after first render (block position)'() { const Bar = defineComponent({}, 'Hello, world!'); @@ -211,7 +210,7 @@ class GeneralStrictModeTest extends RenderTest { }, /\(component\) cannot resolve string values in strict mode templates/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict (expression position)'() { const Bar = defineComponent({}, '{{#let (component this.bar) as |bar|}}{{/let}}', { definition: class extends GlimmerishComponent { @@ -224,7 +223,7 @@ class GeneralStrictModeTest extends RenderTest { }, /Error: Attempted to resolve a dynamic component with a string definition, `bar` in a strict mode template. In strict mode, using strings to resolve component definitions is prohibited. You can instead import the component definition and use it directly./u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) '{{component}} throws an error if a string is used indirectly in strict after first render (expression position)'() { const Bar = defineComponent({}, 'Hello, world!'); @@ -560,7 +559,7 @@ class StaticStrictModeTest extends RenderTest { ); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-component is used as a component'() { const Foo = defineSimpleHelper(() => 'Hello, world!'); const Bar = defineComponent({ Foo }, ''); @@ -570,7 +569,7 @@ class StaticStrictModeTest extends RenderTest { }, /Attempted to load a component, but there wasn't a component manager associated with the definition. The definition was:/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-helper is used as a helper'() { const foo = defineComponent({}, 'Hello, world!'); const Bar = defineComponent({ foo }, '{{#if (foo)}}{{/if}}'); @@ -580,7 +579,7 @@ class StaticStrictModeTest extends RenderTest { }, /Attempted to load a helper, but there wasn't a helper manager associated with the definition. The definition was:/u); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-modifier is used as a modifier'() { const foo = defineSimpleHelper(() => 'Hello, world!'); const Bar = defineComponent({ foo }, '
'); @@ -1104,7 +1103,7 @@ class DynamicStrictModeTest extends RenderTest { this.assertStableRerender(); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-modifier is used as a modifier'() { const foo = defineSimpleHelper(() => 'Hello, world!'); const Bar = defineComponent({}, '
', { @@ -1205,7 +1204,7 @@ class DynamicStrictModeTest extends RenderTest { this.assertStableRerender(); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-component is used as a component'() { const Foo = defineSimpleHelper(() => 'Hello, world!'); const Bar = defineComponent({}, '', { @@ -1273,7 +1272,7 @@ class DynamicStrictModeTest extends RenderTest { this.assertStableRerender(); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Throws an error if a non-helper is used as a helper'() { const foo = defineComponent({}, 'Hello, world!'); const Bar = defineComponent({}, '{{#if (this.foo)}}{{/if}}', { diff --git a/packages/@glimmer-workspace/integration-tests/test/style-warnings-test.ts b/packages/@glimmer-workspace/integration-tests/test/style-warnings-test.ts index 82029008e4e..67c22141d19 100644 --- a/packages/@glimmer-workspace/integration-tests/test/style-warnings-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/style-warnings-test.ts @@ -4,7 +4,6 @@ import { testOverrideGlobalContext } from '@glimmer/global-context'; import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests'; import { assert } from './support'; -import { DEBUG } from '@glimmer/env'; let warnings = 0; let originalContext: GlobalContext | null; @@ -38,7 +37,7 @@ class StyleWarningsTest extends RenderTest { assert.strictEqual(warnings, 0); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'Standard element with dynamic style and element modifier gives you 1 warning'() { this.registerModifier('foo', class {}); this.render('', { diff --git a/packages/@glimmer-workspace/integration-tests/test/updating-test.ts b/packages/@glimmer-workspace/integration-tests/test/updating-test.ts index 46f2c627834..7baa731661b 100644 --- a/packages/@glimmer-workspace/integration-tests/test/updating-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/updating-test.ts @@ -19,7 +19,6 @@ import { } from '@glimmer-workspace/integration-tests'; import { assert } from './support'; -import { DEBUG } from '@glimmer/env'; function makeSafeString(value: string): SafeString { return new SafeStringImpl(value); @@ -873,7 +872,7 @@ class UpdatingTest extends RenderTest { this.assertHTML('
Godfrey
', 'After reset'); } - @test({ skip: !DEBUG }) + @test({ skip: !import.meta.env?.DEV }) 'missing helper'(assert: Assert) { this.registerHelper('hello', () => 'hello'); diff --git a/packages/@glimmer/component/src/-private/base-component-manager.ts b/packages/@glimmer/component/src/-private/base-component-manager.ts index e6652159a90..9f17bfe7fc0 100644 --- a/packages/@glimmer/component/src/-private/base-component-manager.ts +++ b/packages/@glimmer/component/src/-private/base-component-manager.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Arguments, ComponentManager, ComponentCapabilities } from '@glimmer/interfaces'; import { type default as BaseComponent, ARGS_SET } from './component'; @@ -21,7 +20,7 @@ export default abstract class BaseComponentManager< ComponentClass: Constructor, args: Arguments ): GlimmerComponent { - if (DEBUG) { + if (import.meta.env?.DEV) { ARGS_SET.set(args.named, true); } diff --git a/packages/@glimmer/component/src/-private/component.ts b/packages/@glimmer/component/src/-private/component.ts index 8112126309e..401d67936ca 100644 --- a/packages/@glimmer/component/src/-private/component.ts +++ b/packages/@glimmer/component/src/-private/component.ts @@ -1,5 +1,3 @@ -import { DEBUG } from '@glimmer/env'; - const DESTROYING = new WeakMap, boolean>(); const DESTROYED = new WeakMap, boolean>(); @@ -20,11 +18,11 @@ interface ArgsSetMap extends WeakMap, boolean> { has(key: Args): boolean; } -// SAFETY: this only holds because we *only* acces this when `DEBUG` is `true`. +// SAFETY: this only holds because we *only* acces this when `import.meta.env?.DEV` is `true`. // There is not a great way to connect that data in TS at present. export let ARGS_SET: ArgsSetMap; -if (DEBUG) { +if (import.meta.env?.DEV) { ARGS_SET = new WeakMap() as ArgsSetMap; } @@ -233,7 +231,10 @@ export default class GlimmerComponent { * @param args */ constructor(owner: unknown, args: Args) { - if (DEBUG && !(owner !== null && typeof owner === 'object' && ARGS_SET.has(args))) { + if ( + import.meta.env?.DEV && + !(owner !== null && typeof owner === 'object' && ARGS_SET.has(args)) + ) { throw new Error( `You must pass both the owner and args to super() in your component: ${this.constructor.name}. You can pass them directly, or use ...arguments to pass all arguments through.` ); diff --git a/packages/@glimmer/component/src/index.ts b/packages/@glimmer/component/src/index.ts index ba90c043020..4cac6156450 100644 --- a/packages/@glimmer/component/src/index.ts +++ b/packages/@glimmer/component/src/index.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { setComponentManager } from '@ember/component'; import GlimmerComponentManager from './-private/ember-component-manager'; import _GlimmerComponent, { type Args } from './-private/component'; @@ -393,7 +392,7 @@ export default class Component extends _GlimmerComponent { constructor(owner: Owner, args: Args) { super(owner, args); - if (DEBUG && !(owner !== null && typeof owner === 'object')) { + if (import.meta.env?.DEV && !(owner !== null && typeof owner === 'object')) { throw new Error( `You must pass both the owner and args to super() in your component: ${this.constructor.name}. You can pass them directly, or use ...arguments to pass all arguments through.` ); diff --git a/packages/@glimmer/debug-util/lib/debug-to-string.ts b/packages/@glimmer/debug-util/lib/debug-to-string.ts index 23a43bc2b80..c5d57bebe24 100644 --- a/packages/@glimmer/debug-util/lib/debug-to-string.ts +++ b/packages/@glimmer/debug-util/lib/debug-to-string.ts @@ -1,9 +1,8 @@ -import { DEBUG } from '@glimmer/env'; import type { AnyFn } from '@glimmer/interfaces'; let debugToString: undefined | ((value: unknown) => string); -if (DEBUG) { +if (import.meta.env?.DEV) { let getFunctionName = (fn: AnyFn) => { let functionName = fn.name; diff --git a/packages/@glimmer/debug-util/lib/untouchable-this.ts b/packages/@glimmer/debug-util/lib/untouchable-this.ts index 8cf9a2c2376..a7ddc32c640 100644 --- a/packages/@glimmer/debug-util/lib/untouchable-this.ts +++ b/packages/@glimmer/debug-util/lib/untouchable-this.ts @@ -1,8 +1,7 @@ -import { DEBUG } from '@glimmer/env'; /* eslint-disable @typescript-eslint/no-empty-object-type */ export default function buildUntouchableThis(source: string): null | object { let context: null | object = null; - if (DEBUG) { + if (import.meta.env?.DEV) { let assertOnProperty = (property: string | number | symbol) => { let access = typeof property === 'symbol' || typeof property === 'number' diff --git a/packages/@glimmer/debug-util/test/debug-to-string-test.ts b/packages/@glimmer/debug-util/test/debug-to-string-test.ts index 84511a01c8b..a6a73a5673f 100644 --- a/packages/@glimmer/debug-util/test/debug-to-string-test.ts +++ b/packages/@glimmer/debug-util/test/debug-to-string-test.ts @@ -1,11 +1,10 @@ -import { DEBUG } from '@glimmer/env'; /// import { debugToString as maybeDebugToString } from '@glimmer/debug-util'; QUnit.module('debug-to-string tests'); -if (DEBUG) { +if (import.meta.env?.DEV) { const debugToString = maybeDebugToString as (value: unknown) => string; QUnit.test('[debugToString] should be an function in debug mode', (assert) => { assert.deepEqual(typeof maybeDebugToString, 'function'); diff --git a/packages/@glimmer/destroyable/index.ts b/packages/@glimmer/destroyable/index.ts index 6c050178104..3c9381b037a 100644 --- a/packages/@glimmer/destroyable/index.ts +++ b/packages/@glimmer/destroyable/index.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Destroyable, Destructor } from '@glimmer/interfaces'; import { debugToString } from '@glimmer/debug-util'; import { scheduleDestroy, scheduleDestroyed } from '@glimmer/global-context'; @@ -47,7 +46,7 @@ function iterate(collection: OneOrMany, fn: (item: T) => vo } function remove(collection: OneOrMany, item: T, message: string | false) { - if (DEBUG) { + if (import.meta.env?.DEV) { let collectionIsItem = collection === item; let collectionContainsItem = Array.isArray(collection) && collection.indexOf(item) !== -1; @@ -77,7 +76,7 @@ function getDestroyableMeta(destroyable: T): DestroyableM state: LIVE_STATE, }; - if (DEBUG) { + if (import.meta.env?.DEV) { meta.source = destroyable as object; } @@ -88,7 +87,7 @@ function getDestroyableMeta(destroyable: T): DestroyableM } export function associateDestroyableChild(parent: Destroyable, child: T): T { - if (DEBUG && isDestroying(parent)) { + if (import.meta.env?.DEV && isDestroying(parent)) { throw new Error( 'Attempted to associate a destroyable child with an object that is already destroying or destroyed' ); @@ -108,7 +107,7 @@ export function registerDestructor( destructor: Destructor, eager = false ): Destructor { - if (DEBUG && isDestroying(destroyable)) { + if (import.meta.env?.DEV && isDestroying(destroyable)) { throw new Error( 'Attempted to register a destructor with an object that is already destroying or destroyed' ); @@ -130,7 +129,7 @@ export function unregisterDestructor( destructor: Destructor, eager = false ): void { - if (DEBUG && isDestroying(destroyable)) { + if (import.meta.env?.DEV && isDestroying(destroyable)) { throw new Error( 'Attempted to unregister a destructor with an object that is already destroying or destroyed' ); @@ -145,7 +144,8 @@ export function unregisterDestructor( meta[destructorsKey] = remove( meta[destructorsKey], destructor, - DEBUG && 'attempted to remove a destructor that was not registered with the destroyable' + import.meta.env?.DEV && + 'attempted to remove a destructor that was not registered with the destroyable' ); } @@ -184,7 +184,7 @@ function removeChildFromParent(child: Destroyable, parent: Destroyable) { parentMeta.children = remove( parentMeta.children, child, - DEBUG && + import.meta.env?.DEV && "attempted to remove child from parent, but the parent's children did not contain the child. This is likely a bug with destructors." ); } @@ -219,7 +219,7 @@ export function isDestroyed(destroyable: Destroyable) { export let enableDestroyableTracking: undefined | (() => void); export let assertDestroyablesDestroyed: undefined | (() => void); -if (DEBUG) { +if (import.meta.env?.DEV) { let isTesting = false; enableDestroyableTracking = () => { diff --git a/packages/@glimmer/destroyable/test/destroyables-test.ts b/packages/@glimmer/destroyable/test/destroyables-test.ts index 3da761d58d5..08d8c2e9a4d 100644 --- a/packages/@glimmer/destroyable/test/destroyables-test.ts +++ b/packages/@glimmer/destroyable/test/destroyables-test.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { GlobalContext } from '@glimmer/global-context'; import { unwrap } from '@glimmer/debug-util'; import { @@ -374,7 +373,7 @@ module('Destroyables', (hooks) => { assert.verifySteps(['child destructor', 'parent destructor'], 'destructors run bottom up'); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('attempting to unregister a destructor that was not registered throws an error', (assert) => { assert.throws(() => { unregisterDestructor({}, () => 123); diff --git a/packages/@glimmer/encoder/lib/encoder.ts b/packages/@glimmer/encoder/lib/encoder.ts index ce9d19be6eb..63801d68f3e 100644 --- a/packages/@glimmer/encoder/lib/encoder.ts +++ b/packages/@glimmer/encoder/lib/encoder.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CompilerBuffer, InstructionEncoder, @@ -27,7 +26,7 @@ export class InstructionEncoderImpl implements InstructionEncoder { this.buffer.push(first); for (const op of args) { - if (DEBUG && typeof op === 'number' && op > MAX_SIZE) { + if (import.meta.env?.DEV && typeof op === 'number' && op > MAX_SIZE) { throw new Error(`Operand over 32-bits. Got ${op}.`); } this.buffer.push(op); diff --git a/packages/@glimmer/global-context/index.ts b/packages/@glimmer/global-context/index.ts index 125e19a1074..47790fcdc68 100644 --- a/packages/@glimmer/global-context/index.ts +++ b/packages/@glimmer/global-context/index.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ /** @@ -127,7 +126,7 @@ export function debugAssert( msg: string | (() => string), options?: { id: string } ): asserts test { - if (DEBUG && assert) { + if (import.meta.env?.DEV && assert) { assert(test, typeof msg === 'string' ? msg : msg(), options); } } @@ -173,7 +172,7 @@ export interface GlobalContext { let globalContextWasSet = false; export default function setGlobalContext(context: GlobalContext) { - if (DEBUG) { + if (import.meta.env?.DEV) { if (globalContextWasSet) { throw new Error('Attempted to set the global context twice. This should only be set once.'); } @@ -200,7 +199,7 @@ export let testOverrideGlobalContext: | ((context: Partial | null) => GlobalContext | null) | undefined; -if (DEBUG) { +if (import.meta.env?.DEV) { assertGlobalContextWasSet = () => { if (!globalContextWasSet) { throw new Error( diff --git a/packages/@glimmer/manager/lib/internal/api.ts b/packages/@glimmer/manager/lib/internal/api.ts index 96a1daa7703..d6127aac69e 100644 --- a/packages/@glimmer/manager/lib/internal/api.ts +++ b/packages/@glimmer/manager/lib/internal/api.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Helper, InternalComponentManager, @@ -39,7 +38,7 @@ function setManager( manager: object, obj: Def ): Def { - if (DEBUG) { + if (import.meta.env?.DEV) { debugAssert( obj !== null && (typeof obj === 'object' || typeof obj === 'function'), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme @@ -96,7 +95,7 @@ export function getInternalModifierManager( definition: object, isOptional?: true ): InternalModifierManager | null { - if (DEBUG) { + if (import.meta.env?.DEV) { debugAssert( (typeof definition === 'object' && definition !== null) || typeof definition === 'function', () => @@ -108,7 +107,7 @@ export function getInternalModifierManager( const manager = getManager(MODIFIER_MANAGERS, definition); if (manager === undefined) { - if (DEBUG) { + if (import.meta.env?.DEV) { debugAssert( isOptional, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme @@ -161,7 +160,7 @@ export function getInternalHelperManager( return manager; } else if (isOptional === true) { return null; - } else if (DEBUG) { + } else if (import.meta.env?.DEV) { throw new Error( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme `Attempted to load a helper, but there wasn't a helper manager associated with the definition. The definition was: ${debugToString!( diff --git a/packages/@glimmer/manager/lib/public/component.ts b/packages/@glimmer/manager/lib/public/component.ts index f8f9be9b7a7..4bfbe2fd0bf 100644 --- a/packages/@glimmer/manager/lib/public/component.ts +++ b/packages/@glimmer/manager/lib/public/component.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Arguments, ComponentCapabilities, @@ -45,7 +44,7 @@ export function componentCapabilities implements InternalHel delegate = factory(owner); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme - if (DEBUG && !FROM_CAPABILITIES!.has(delegate.capabilities)) { + if (import.meta.env?.DEV && !FROM_CAPABILITIES!.has(delegate.capabilities)) { // TODO: This error message should make sense in both Ember and Glimmer https://github.com/glimmerjs/glimmer-vm/issues/1200 throw new Error( `Custom helper managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.23')\` (imported via \`import { capabilities } from '@ember/helper';\`). Received: \`${JSON.stringify( @@ -124,7 +123,7 @@ export class CustomHelperManager implements InternalHel let cache = createComputeRef( () => manager.getValue(bucket), null, - DEBUG && manager.getDebugName && manager.getDebugName(definition) + import.meta.env?.DEV && manager.getDebugName && manager.getDebugName(definition) ); if (hasDestroyable(manager)) { @@ -135,7 +134,7 @@ export class CustomHelperManager implements InternalHel } else if (hasDestroyable(manager)) { let ref = createConstRef( undefined, - DEBUG && (manager.getDebugName?.(definition) ?? 'unknown helper') + import.meta.env?.DEV && (manager.getDebugName?.(definition) ?? 'unknown helper') ); associateDestroyableChild(ref, manager.getDestroyable(bucket)); diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index ef5b74b5b08..958831efa9e 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Arguments, CapturedArguments, @@ -87,7 +86,7 @@ export class CustomModifierManager< delegate = factory(owner); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme - if (DEBUG && !FROM_CAPABILITIES!.has(delegate.capabilities)) { + if (import.meta.env?.DEV && !FROM_CAPABILITIES!.has(delegate.capabilities)) { // TODO: This error message should make sense in both Ember and Glimmer https://github.com/glimmerjs/glimmer-vm/issues/1200 throw new Error( `Custom modifier managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.22')\` (imported via \`import { capabilities } from '@ember/modifier';\`). Received: \`${JSON.stringify( diff --git a/packages/@glimmer/manager/lib/public/template.ts b/packages/@glimmer/manager/lib/public/template.ts index 883a0f99b28..88b4d8f7590 100644 --- a/packages/@glimmer/manager/lib/public/template.ts +++ b/packages/@glimmer/manager/lib/public/template.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { TemplateFactory } from '@glimmer/interfaces'; import { debugToString } from '@glimmer/debug-util'; @@ -7,12 +6,15 @@ const TEMPLATES: WeakMap = new WeakMap(); const getPrototypeOf = Reflect.getPrototypeOf; export function setComponentTemplate(factory: TemplateFactory, obj: object) { - if (DEBUG && !(obj !== null && (typeof obj === 'object' || typeof obj === 'function'))) { + if ( + import.meta.env?.DEV && + !(obj !== null && (typeof obj === 'object' || typeof obj === 'function')) + ) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme throw new Error(`Cannot call \`setComponentTemplate\` on \`${debugToString!(obj)}\``); } - if (DEBUG && TEMPLATES.has(obj)) { + if (import.meta.env?.DEV && TEMPLATES.has(obj)) { throw new Error( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme `Cannot call \`setComponentTemplate\` multiple times on the same class (\`${debugToString!( diff --git a/packages/@glimmer/manager/lib/util/args-proxy.ts b/packages/@glimmer/manager/lib/util/args-proxy.ts index e97a1fbe20f..ba82af96280 100644 --- a/packages/@glimmer/manager/lib/util/args-proxy.ts +++ b/packages/@glimmer/manager/lib/util/args-proxy.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Arguments, CapturedArguments, @@ -86,7 +85,7 @@ class NamedArgsProxy implements ProxyHandler<{}> { // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- @fixme getOwnPropertyDescriptor(_target: {}, prop: string | number | symbol) { - if (DEBUG && !(prop in this.named)) { + if (import.meta.env?.DEV && !(prop in this.named)) { throw new Error( `args proxies do not have real property descriptors, so you should never need to call getOwnPropertyDescriptor yourself. This code exists for enumerability, such as in for-in loops and Object.keys(). Attempted to get the descriptor for \`${String( prop @@ -152,7 +151,7 @@ export const argsProxyFor = ( const namedTarget = Object.create(null); const positionalTarget: unknown[] = []; - if (DEBUG) { + if (import.meta.env?.DEV) { const setHandler = function (_target: unknown, prop: symbol | string | number): never { throw new Error( `You attempted to set ${String( diff --git a/packages/@glimmer/manager/lib/util/capabilities.ts b/packages/@glimmer/manager/lib/util/capabilities.ts index 7254e129804..8710443fc05 100644 --- a/packages/@glimmer/manager/lib/util/capabilities.ts +++ b/packages/@glimmer/manager/lib/util/capabilities.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { AttributeHookCapability, Capabilities, @@ -27,10 +26,10 @@ import type { import { check, CheckNumber } from '@glimmer/debug'; import { InternalComponentCapabilities } from '@glimmer/vm'; -export const FROM_CAPABILITIES = DEBUG ? new WeakSet() : undefined; +export const FROM_CAPABILITIES = import.meta.env?.DEV ? new WeakSet() : undefined; export function buildCapabilities(capabilities: T): T & Capabilities { - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme FROM_CAPABILITIES!.add(capabilities); Object.freeze(capabilities); diff --git a/packages/@glimmer/manager/test/managers-test.ts b/packages/@glimmer/manager/test/managers-test.ts index 2d28b602635..c5f37b5afe3 100644 --- a/packages/@glimmer/manager/test/managers-test.ts +++ b/packages/@glimmer/manager/test/managers-test.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ComponentManager, HelperManager, @@ -104,7 +103,7 @@ module('Managers', () => { ); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('throws if multiple component managers associated with the same definition', (assert) => { let definition = setInternalComponentManager({} as any, {}); @@ -206,7 +205,7 @@ module('Managers', () => { assert.strictEqual(instance1, helper, 'manager is the internal helper'); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('throws if multiple helper managers associated with the same definition', (assert) => { let definition = setInternalHelperManager(() => { return {} as any; @@ -317,7 +316,7 @@ module('Managers', () => { ); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('throws if multiple modifier managers associated with the same definition', (assert) => { let definition = setModifierManager(() => { return {} as any; @@ -377,7 +376,7 @@ module('Managers', () => { }); function assertPrimitiveUsage(assert: Assert, setManager: any) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(0); return; } diff --git a/packages/@glimmer/opcode-compiler/lib/opcode-builder/encoder.ts b/packages/@glimmer/opcode-compiler/lib/opcode-builder/encoder.ts index e0d71691977..fd9c025ae80 100644 --- a/packages/@glimmer/opcode-compiler/lib/opcode-builder/encoder.ts +++ b/packages/@glimmer/opcode-compiler/lib/opcode-builder/encoder.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { BlockMetadata, BuilderOp, @@ -165,7 +164,7 @@ export class EncoderImpl implements Encoder { ): void { let { heap } = this; - if (DEBUG && (type as number) > TYPE_SIZE) { + if (import.meta.env?.DEV && (type as number) > TYPE_SIZE) { throw new Error(`Opcode type over 8-bits. Got ${type}.`); } diff --git a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/resolution.ts b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/resolution.ts index b4cb62f09f0..7d94e588496 100644 --- a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/resolution.ts +++ b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/resolution.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { BlockMetadata, BlockSymbolNames, @@ -56,7 +55,7 @@ interface ResolvedBlockMetadata extends BlockMetadata { } function assertResolverInvariants(meta: BlockMetadata): ResolvedBlockMetadata { - if (DEBUG) { + if (import.meta.env?.DEV) { if (!meta.symbols.upvars) { throw new Error( 'Attempted to resolve a component, helper, or modifier, but no free vars were found' @@ -88,7 +87,7 @@ export function resolveComponent( let type = expr[0]; - if (DEBUG && expr[0] === SexpOpcodes.GetStrictKeyword) { + if (import.meta.env?.DEV && expr[0] === SexpOpcodes.GetStrictKeyword) { localAssert(!meta.isStrictMode, 'Strict mode errors should already be handled at compile time'); throw new Error( @@ -126,7 +125,7 @@ export function resolveComponent( let name = unwrap(upvars[expr[1]]); let definition = resolver?.lookupComponent?.(name, owner) ?? null; - if (DEBUG && (typeof definition !== 'object' || definition === null)) { + if (import.meta.env?.DEV && (typeof definition !== 'object' || definition === null)) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -176,7 +175,7 @@ export function resolveHelper( let name = unwrap(upvars[expr[1]]); let helper = resolver?.lookupHelper?.(name, owner) ?? null; - if (DEBUG && helper === null) { + if (import.meta.env?.DEV && helper === null) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -224,7 +223,7 @@ export function resolveModifier( let name = unwrap(upvars[expr[1]]); let modifier = resolver?.lookupBuiltInModifier?.(name) ?? null; - if (DEBUG && modifier === null) { + if (import.meta.env?.DEV && modifier === null) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -245,7 +244,7 @@ export function resolveModifier( let name = unwrap(upvars[expr[1]]); let modifier = resolver?.lookupModifier?.(name, owner) ?? null; - if (DEBUG && modifier === null) { + if (import.meta.env?.DEV && modifier === null) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -301,7 +300,7 @@ export function resolveComponentOrHelper( let helper = constants.helper(definition as object, null, true); - if (DEBUG && helper === null) { + if (import.meta.env?.DEV && helper === null) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -340,7 +339,7 @@ export function resolveComponentOrHelper( } else { let helper = resolver?.lookupHelper?.(name, owner) ?? null; - if (DEBUG && helper === null) { + if (import.meta.env?.DEV && helper === null) { localAssert( !meta.isStrictMode, 'Strict mode errors should already be handled at compile time' @@ -452,7 +451,7 @@ function lookupBuiltInHelper( let name = unwrap(upvars[expr[1]]); let helper = resolver?.lookupBuiltInHelper?.(name) ?? null; - if (DEBUG && helper === null) { + if (import.meta.env?.DEV && helper === null) { localAssert(!meta.isStrictMode, 'Strict mode errors should already be handled at compile time'); // Keyword helper did not exist, which means that we're attempting to use a diff --git a/packages/@glimmer/reference/lib/iterable.ts b/packages/@glimmer/reference/lib/iterable.ts index f0a60fe9c0f..fdbaec5fb6b 100644 --- a/packages/@glimmer/reference/lib/iterable.ts +++ b/packages/@glimmer/reference/lib/iterable.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Dict, Nullable } from '@glimmer/interfaces'; import { getPath, toIterator } from '@glimmer/global-context'; import { EMPTY_ARRAY, isIndexable } from '@glimmer/util'; @@ -49,7 +48,7 @@ const IDENTITY: KeyFor = (item) => { }; function keyForPath(path: string): KeyFor { - if (DEBUG && path[0] === '@') { + if (import.meta.env?.DEV && path[0] === '@') { throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`); } return uniqueKeyFor((item) => getPath(item as object, path)); diff --git a/packages/@glimmer/reference/lib/reference.ts b/packages/@glimmer/reference/lib/reference.ts index e58fb46cf8a..fd9a1d3e1c5 100644 --- a/packages/@glimmer/reference/lib/reference.ts +++ b/packages/@glimmer/reference/lib/reference.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ComputeReference, ConstantReference, @@ -65,7 +64,7 @@ export function createPrimitiveRef(value: T, debugLabel: false | string): Referen ref.lastValue = value; ref.tag = CONSTANT_TAG; - if (DEBUG) { + if (import.meta.env?.DEV) { ref.debugLabel = debugLabel as string; } @@ -96,7 +95,7 @@ export function createUnboundRef(value: T, debugLabel: false | string): Refer ref.lastValue = value; ref.tag = CONSTANT_TAG; - if (DEBUG) { + if (import.meta.env?.DEV) { ref.debugLabel = debugLabel as string; } @@ -113,7 +112,7 @@ export function createComputeRef( ref.compute = compute; ref.update = update; - if (DEBUG) { + if (import.meta.env?.DEV) { ref.debugLabel = `(result of a \`${debugLabel}\` helper)`; } @@ -168,10 +167,13 @@ export function valueForRef(_ref: Reference): T { if (tag === null || !validateTag(tag, lastRevision)) { const { compute } = ref; - const newTag = track(() => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme - lastValue = ref.lastValue = compute!(); - }, DEBUG && ref.debugLabel); + const newTag = track( + () => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme + lastValue = ref.lastValue = compute!(); + }, + import.meta.env?.DEV && ref.debugLabel + ); tag = ref.tag = newTag; @@ -215,7 +217,7 @@ export function childRefFor(_parentRef: Reference, path: string): Reference { if (isDict(parent)) { child = createUnboundRef( (parent as Record)[path], - DEBUG && `${parentRef.debugLabel}.${path}` + import.meta.env?.DEV && `${parentRef.debugLabel}.${path}` ); } else { child = UNDEFINED_REFERENCE; @@ -238,7 +240,7 @@ export function childRefFor(_parentRef: Reference, path: string): Reference { } ); - if (DEBUG) { + if (import.meta.env?.DEV) { child.debugLabel = `${parentRef.debugLabel}.${path}`; } } @@ -260,7 +262,7 @@ export function childRefFromParts(root: Reference, parts: string[]): Reference { export let createDebugAliasRef: undefined | ((debugLabel: string, inner: Reference) => Reference); -if (DEBUG) { +if (import.meta.env?.DEV) { createDebugAliasRef = (debugLabel: string, inner: Reference) => { const update = isUpdatableRef(inner) ? (value: unknown): void => updateRef(inner, value) : null; const ref = createComputeRef(() => valueForRef(inner), update); diff --git a/packages/@glimmer/reference/test/references-test.ts b/packages/@glimmer/reference/test/references-test.ts index 7d46ac70c5d..ac1e2610eb9 100644 --- a/packages/@glimmer/reference/test/references-test.ts +++ b/packages/@glimmer/reference/test/references-test.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { GlobalContext } from '@glimmer/global-context'; import { unwrap } from '@glimmer/debug-util'; import { testOverrideGlobalContext } from '@glimmer/global-context'; @@ -36,7 +35,7 @@ class TrackedDict { return (this.data[key] = value); } } -if (DEBUG) { +if (import.meta.env?.DEV) { module('References', (hooks) => { let originalContext: GlobalContext | null; let getCount = 0; @@ -385,7 +384,7 @@ if (DEBUG) { }); }); - if (DEBUG) { + if (import.meta.env?.DEV) { module('debugAliasRef', () => { test('debug alias refs are transparent', (assert) => { class Foo { diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index a8091130ec7..b2477fa2bfe 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Bounds, CapabilityMask, @@ -167,7 +166,7 @@ APPEND_OPCODES.add(VM_RESOLVE_DYNAMIC_COMPONENT_OP, (vm, { op1: _isStrict }) => let definition: ComponentDefinition | CurriedValue; if (typeof component === 'string') { - if (DEBUG && isStrict) { + if (import.meta.env?.DEV && isStrict) { throw new Error( `Attempted to resolve a dynamic component with a string definition, \`${component}\` in a strict mode template. In strict mode, using strings to resolve component definitions is prohibited. You can instead import the component definition and use it directly.` ); @@ -193,7 +192,10 @@ APPEND_OPCODES.add(VM_RESOLVE_CURRIED_COMPONENT_OP, (vm) => { let definition: CurriedValue | ComponentDefinition | null; - if (DEBUG && !(typeof value === 'function' || (typeof value === 'object' && value !== null))) { + if ( + import.meta.env?.DEV && + !(typeof value === 'function' || (typeof value === 'object' && value !== null)) + ) { throw new Error( `Expected a component definition, but received ${value}. You may have accidentally done <${ref.debugLabel}>, where "${ref.debugLabel}" was a string instead of a curried component definition. You must either use the component definition directly, or use the {{component}} helper to create a curried component definition when invoking dynamically.` ); @@ -204,7 +206,7 @@ APPEND_OPCODES.add(VM_RESOLVE_CURRIED_COMPONENT_OP, (vm) => { } else { definition = constants.component(value as object, vm.getOwner(), true); - if (DEBUG && definition === null) { + if (import.meta.env?.DEV && definition === null) { throw new Error( `Expected a dynamic component definition, but received an object or function that did not have a component manager associated with it. The dynamic invocation was \`<${ ref.debugLabel @@ -415,7 +417,7 @@ APPEND_OPCODES.add(VM_REGISTER_COMPONENT_DESTRUCTOR_OP, (vm, { op1: register }) let d = manager.getDestroyable(state); if ( - DEBUG && + import.meta.env?.DEV && !managerHasCapability(manager, capabilities, InternalComponentCapabilities.willDestroy) && d !== null && (typeof 'willDestroy') in d @@ -431,7 +433,7 @@ APPEND_OPCODES.add(VM_REGISTER_COMPONENT_DESTRUCTOR_OP, (vm, { op1: register }) APPEND_OPCODES.add(VM_BEGIN_COMPONENT_TRANSACTION_OP, (vm, { op1: register }) => { let name; - if (DEBUG) { + if (import.meta.env?.DEV) { let { definition, manager } = check( vm.fetchValue(check(register, CheckRegister)), CheckComponentInstance @@ -788,7 +790,7 @@ APPEND_OPCODES.add(VM_MAIN_OP, (vm, { op1: register }) => { APPEND_OPCODES.add(VM_POPULATE_LAYOUT_OP, (vm, { op1: register }) => { let { stack } = vm; - // In import.meta.env.DEV handles could be ErrHandle objects + // In DEV mode handles could be ErrHandle objects let handle = check(stack.pop(), CheckHandle); let table = check(stack.pop(), CheckProgramSymbolTable); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts index a24a65e9077..f650e090758 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { CURRIED_COMPONENT, CURRIED_HELPER, @@ -58,7 +57,11 @@ function toDynamicContentType(value: unknown) { if (isCurriedType(value, CURRIED_COMPONENT) || hasInternalComponentManager(value)) { return ContentType.Component; } else { - if (DEBUG && !isCurriedType(value, CURRIED_HELPER) && !hasInternalHelperManager(value)) { + if ( + import.meta.env?.DEV && + !isCurriedType(value, CURRIED_HELPER) && + !hasInternalHelperManager(value) + ) { throw new Error( // eslint-disable-next-line @typescript-eslint/no-base-to-string -- @fixme `Attempted use a dynamic value as a component or helper, but that value did not have an associated component or helper manager. The value was: ${value}` diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts index 9c0d378b123..64ccc84439f 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CapturedPositionalArguments, Environment, @@ -241,7 +240,7 @@ APPEND_OPCODES.add(VM_DYNAMIC_MODIFIER_OP, (vm) => { let manager = getInternalModifierManager(hostDefinition, true); if (manager === null) { - if (DEBUG) { + if (import.meta.env?.DEV) { throw new Error( `Expected a dynamic modifier definition, but received an object or function that did not have a modifier manager associated with it. The dynamic invocation was \`{{${ ref.debugLabel diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts index 326142fdc2a..358df6b047f 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CapturedPositionalArguments, CurriedType, @@ -79,8 +78,8 @@ APPEND_OPCODES.add(VM_CURRY_OP, (vm, { op1: type, op2: _isStrict }) => { let isStrict = false; - if (DEBUG) { - // strict check only happens in import.meta.env.DEV builds, no reason to load it otherwise + if (import.meta.env?.DEV) { + // strict check only happens in DEV builds, no reason to load it otherwise isStrict = vm.constants.getValue(decodeHandle(_isStrict)); } diff --git a/packages/@glimmer/runtime/lib/component/resolve.ts b/packages/@glimmer/runtime/lib/component/resolve.ts index 5287d0bdfa7..c943cbdea97 100644 --- a/packages/@glimmer/runtime/lib/component/resolve.ts +++ b/packages/@glimmer/runtime/lib/component/resolve.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ClassicResolver, ComponentDefinition, @@ -20,7 +19,7 @@ export function resolveComponent( expect(owner, 'BUG: expected owner when looking up component') ) ?? null; - if (DEBUG && !definition) { + if (import.meta.env?.DEV && !definition) { throw new Error( `Attempted to resolve \`${name}\`, which was expected to be a component, but nothing was found.` ); diff --git a/packages/@glimmer/runtime/lib/debug-render-tree.ts b/packages/@glimmer/runtime/lib/debug-render-tree.ts index b48626fb8a3..3f22a3309c8 100644 --- a/packages/@glimmer/runtime/lib/debug-render-tree.ts +++ b/packages/@glimmer/runtime/lib/debug-render-tree.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Bounds, CapturedRenderNode, @@ -33,7 +32,7 @@ export class Ref { } release(): void { - if (DEBUG && this.value === null) { + if (import.meta.env?.DEV && this.value === null) { throw new Error('BUG: double release?'); } @@ -84,7 +83,7 @@ export default class DebugRenderTreeImpl< } didRender(state: TBucket, bounds: Bounds): void { - if (DEBUG && this.stack.current !== state) { + if (import.meta.env?.DEV && this.stack.current !== state) { // eslint-disable-next-line @typescript-eslint/no-base-to-string throw new Error(`BUG: expecting ${this.stack.current}, got ${state}`); } @@ -134,7 +133,7 @@ export default class DebugRenderTreeImpl< } private exit(): void { - if (DEBUG && this.stack.size === 0) { + if (import.meta.env?.DEV && this.stack.size === 0) { throw new Error('BUG: unbalanced pop'); } @@ -146,7 +145,7 @@ export default class DebugRenderTreeImpl< } private appendChild(node: InternalRenderNode, state: TBucket): void { - if (DEBUG && this.refs.has(state)) { + if (import.meta.env?.DEV && this.refs.has(state)) { throw new Error('BUG: child already appended'); } diff --git a/packages/@glimmer/runtime/lib/environment.ts b/packages/@glimmer/runtime/lib/environment.ts index dfc6ad3a765..6f4d93e595a 100644 --- a/packages/@glimmer/runtime/lib/environment.ts +++ b/packages/@glimmer/runtime/lib/environment.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ClassicResolver, ComponentInstanceWithCreate, @@ -64,7 +63,7 @@ class TransactionImpl implements Transaction { if (modifierTag !== null) { let tag = track( () => manager.install(state), - DEBUG && + import.meta.env?.DEV && `- While rendering:\n (instance of a \`${ definition.resolvedName || manager.getDebugName(definition.state) }\` modifier)` @@ -81,7 +80,7 @@ class TransactionImpl implements Transaction { if (modifierTag !== null) { let tag = track( () => manager.update(state), - DEBUG && + import.meta.env?.DEV && `- While rendering:\n (instance of a \`${ definition.resolvedName || manager.getDebugName(definition.state) }\` modifier)` @@ -120,7 +119,7 @@ export class EnvironmentImpl implements Environment { } else if (options.document) { this.appendOperations = new DOMTreeConstruction(options.document); this.updateOperations = new DOMChangesImpl(options.document); - } else if (DEBUG) { + } else if (import.meta.env?.DEV) { throw new Error('you must pass document or appendOperations to a new runtime'); } } diff --git a/packages/@glimmer/runtime/lib/helpers/fn.ts b/packages/@glimmer/runtime/lib/helpers/fn.ts index 1fbf2b89305..280df04dd8c 100644 --- a/packages/@glimmer/runtime/lib/helpers/fn.ts +++ b/packages/@glimmer/runtime/lib/helpers/fn.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { AnyFn, CapturedArguments } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; import { check } from '@glimmer/debug'; @@ -82,7 +81,7 @@ export const fn = internalHelper(({ positional }: CapturedArguments) => { return (...invocationArgs: unknown[]) => { let [fn, ...args] = reifyPositional(positional); - if (DEBUG) assertCallbackIsFn(callbackRef); + if (import.meta.env?.DEV) assertCallbackIsFn(callbackRef); if (isInvokableRef(callbackRef)) { let value = args.length > 0 ? args[0] : invocationArgs[0]; diff --git a/packages/@glimmer/runtime/lib/helpers/invoke.ts b/packages/@glimmer/runtime/lib/helpers/invoke.ts index e32ab87979b..7c55f7450dc 100644 --- a/packages/@glimmer/runtime/lib/helpers/invoke.ts +++ b/packages/@glimmer/runtime/lib/helpers/invoke.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Arguments, InternalHelperManager } from '@glimmer/interfaces'; import type { Cache } from '@glimmer/validator'; import { associateDestroyableChild, isDestroyed, isDestroying } from '@glimmer/destroyable'; @@ -8,11 +7,13 @@ import { createCache, getValue } from '@glimmer/validator'; import { EMPTY_ARGS, EMPTY_NAMED, EMPTY_POSITIONAL } from '../vm/arguments'; -let ARGS_CACHES = DEBUG ? new WeakMap>>() : undefined; +let ARGS_CACHES = import.meta.env?.DEV + ? new WeakMap>>() + : undefined; function getArgs(proxy: SimpleArgsProxy): Partial { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme - return getValue(DEBUG ? ARGS_CACHES!.get(proxy)! : proxy.argsCache!)!; + return getValue(import.meta.env?.DEV ? ARGS_CACHES!.get(proxy)! : proxy.argsCache!)!; } class SimpleArgsProxy { @@ -24,7 +25,7 @@ class SimpleArgsProxy { ) { let argsCache = createCache(() => computeArgs(context)); - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme ARGS_CACHES!.set(this, argsCache); Object.freeze(this); @@ -49,7 +50,7 @@ export function invokeHelper( definition: object, computeArgs?: (context: object) => Partial ): Cache { - if (DEBUG && (typeof context !== 'object' || context === null)) { + if (import.meta.env?.DEV && (typeof context !== 'object' || context === null)) { throw new Error( `Expected a context object to be passed as the first parameter to invokeHelper, got ${context}` ); @@ -59,7 +60,7 @@ export function invokeHelper( const internalManager = getInternalHelperManager(definition); - if (DEBUG && typeof internalManager === 'function') { + if (import.meta.env?.DEV && typeof internalManager === 'function') { throw new Error( 'Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.' ); @@ -73,7 +74,7 @@ export function invokeHelper( if (hasValue(manager)) { cache = createCache(() => { - if (DEBUG && (isDestroying(cache) || isDestroyed(cache))) { + if (import.meta.env?.DEV && (isDestroying(cache) || isDestroyed(cache))) { throw new Error( `You attempted to get the value of a helper after the helper was destroyed, which is not allowed` ); diff --git a/packages/@glimmer/runtime/lib/modifiers/on.ts b/packages/@glimmer/runtime/lib/modifiers/on.ts index 7c438230b19..415765a4b20 100644 --- a/packages/@glimmer/runtime/lib/modifiers/on.ts +++ b/packages/@glimmer/runtime/lib/modifiers/on.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CapturedArguments, InternalModifierManager, @@ -86,7 +85,7 @@ export class OnModifierState { }. While rendering:\n\n${args.positional[1]?.debugLabel ?? `{unlabeled value}`}` ); - if (DEBUG && args.positional.length !== 2) { + if (import.meta.env?.DEV && args.positional.length !== 2) { throw new Error( `You can only pass two positional arguments (event name and callback) to the \`on\` modifier, but you provided ${args.positional.length}. Consider using the \`fn\` helper to provide additional arguments to the \`on\` callback.` ); @@ -96,7 +95,7 @@ export class OnModifierState { let passive: boolean | undefined = undefined; let capture: boolean | undefined = undefined; - if (DEBUG) { + if (import.meta.env?.DEV) { let { once: _once, passive: _passive, capture: _capture, ...extra } = reifyNamed(args.named); once = check(_once, CheckOr(CheckBoolean, CheckUndefined), (actual) => { @@ -169,7 +168,7 @@ export class OnModifierState { if (shouldUpdate) { let callback = userProvidedCallback; - if (DEBUG) { + if (import.meta.env?.DEV) { callback = userProvidedCallback.bind(untouchableContext); if (passive) { diff --git a/packages/@glimmer/runtime/lib/references/curry-value.ts b/packages/@glimmer/runtime/lib/references/curry-value.ts index ab1e01433e8..b779d7c86ce 100644 --- a/packages/@glimmer/runtime/lib/references/curry-value.ts +++ b/packages/@glimmer/runtime/lib/references/curry-value.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CapturedArguments, ClassicResolver, @@ -39,7 +38,7 @@ export default function createCurryRef( // Only components should enter this path, as helpers and modifiers do not // support string based resolution - if (DEBUG) { + if (import.meta.env?.DEV) { if (isStrict) { throw new Error( `Attempted to resolve a dynamic component with a string definition, \`${value}\` in a strict mode template. In strict mode, using strings to resolve component definitions is prohibited. You can instead import the component definition and use it directly.` diff --git a/packages/@glimmer/runtime/lib/render.ts b/packages/@glimmer/runtime/lib/render.ts index ea375633868..c660664dbb2 100644 --- a/packages/@glimmer/runtime/lib/render.ts +++ b/packages/@glimmer/runtime/lib/render.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { CompilableProgram, ComponentDefinitionState, @@ -28,7 +27,7 @@ class TemplateIteratorImpl implements TemplateIterator { } sync(): RenderResult { - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme return debug.runInTrackingTransaction!(() => this.vm.execute(), '- While rendering:'); } else { diff --git a/packages/@glimmer/runtime/lib/vm/append.ts b/packages/@glimmer/runtime/lib/vm/append.ts index 5d43072ccf5..2ec02614a08 100644 --- a/packages/@glimmer/runtime/lib/vm/append.ts +++ b/packages/@glimmer/runtime/lib/vm/append.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { BlockMetadata, CompilableTemplate, @@ -223,7 +222,7 @@ export class VM { context: EvaluationContext, tree: TreeBuilder ) { - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme assertGlobalContextWasSet!(); } @@ -724,7 +723,7 @@ export class VM { /// EXECUTION execute(initialize?: (vm: this) => void): RenderResult { - if (DEBUG) { + if (import.meta.env?.DEV) { let hasErrored = true; try { let value = this._execute(initialize); diff --git a/packages/@glimmer/runtime/lib/vm/arguments.ts b/packages/@glimmer/runtime/lib/vm/arguments.ts index 02ad9ab9af1..a5d82031110 100644 --- a/packages/@glimmer/runtime/lib/vm/arguments.ts +++ b/packages/@glimmer/runtime/lib/vm/arguments.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ArgumentError, BlockArguments, @@ -308,7 +307,7 @@ export class NamedArgumentsImpl implements NamedArguments { let ref = stack.get(idx, base); - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme return createDebugAliasRef!(atNames ? name : `@${name}`, ref); } else { @@ -321,7 +320,7 @@ export class NamedArgumentsImpl implements NamedArguments { let map = dict(); for (const [i, name] of enumerate(names)) { - if (DEBUG) { + if (import.meta.env?.DEV) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme map[name] = createDebugAliasRef!(`@${name}`, unwrap(references[i])); } else { diff --git a/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts b/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts index d38e139acbe..d61d00ac88b 100644 --- a/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts +++ b/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { AttributeCursor, AttributeOperation, @@ -28,7 +27,7 @@ export function dynamicAttribute( const { tagName, namespaceURI } = element; const attribute = { element, name: attr, namespace }; - if (DEBUG && attr === 'style' && !isTrusting) { + if (import.meta.env?.DEV && attr === 'style' && !isTrusting) { return new DebugStyleAttributeManager(attribute); } @@ -242,7 +241,7 @@ let DebugStyleAttributeManager: { new (attribute: AttributeCursor): AttributeOperation; }; -if (DEBUG) { +if (import.meta.env?.DEV) { DebugStyleAttributeManager = class extends SimpleDynamicAttribute { override set(dom: TreeBuilder, value: unknown, env: Environment): void { warnIfStyleNotTrusted(value); diff --git a/packages/@glimmer/runtime/lib/vm/update.ts b/packages/@glimmer/runtime/lib/vm/update.ts index 06386416da2..d5268bed71d 100644 --- a/packages/@glimmer/runtime/lib/vm/update.ts +++ b/packages/@glimmer/runtime/lib/vm/update.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { AppendingBlock, Bounds, @@ -42,7 +41,7 @@ export class UpdatingVM implements IUpdatingVM { } execute(opcodes: UpdatingOpcode[], handler: ExceptionHandler) { - if (DEBUG) { + if (import.meta.env?.DEV) { let hasErrored = true; try { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme diff --git a/packages/@glimmer/syntax/lib/source/source.ts b/packages/@glimmer/syntax/lib/source/source.ts index d787274bff8..0e5fd30bc6c 100644 --- a/packages/@glimmer/syntax/lib/source/source.ts +++ b/packages/@glimmer/syntax/lib/source/source.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Nullable } from '@glimmer/interfaces'; import { localAssert, setLocalDebugType } from '@glimmer/debug-util'; @@ -80,7 +79,7 @@ export class Source { if (seenChars + column > nextLine) return nextLine; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (DEBUG) { + if (import.meta.env?.DEV) { let roundTrip = this.hbsPosFor(seenChars + column); localAssert(roundTrip !== null, `the returned offset failed to round-trip`); localAssert( diff --git a/packages/@glimmer/validator/lib/debug.ts b/packages/@glimmer/validator/lib/debug.ts index 3578a060562..3ebeff44140 100644 --- a/packages/@glimmer/validator/lib/debug.ts +++ b/packages/@glimmer/validator/lib/debug.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; /* eslint-disable @typescript-eslint/no-non-null-assertion -- @fixme */ import type { Tag } from '@glimmer/interfaces'; import { asPresentArray, getLast } from '@glimmer/debug-util'; @@ -31,7 +30,7 @@ interface Transaction { debugLabel?: string | undefined; } -if (DEBUG) { +if (import.meta.env?.DEV) { let CONSUMED_TAGS: WeakMap | null = null; const TRANSACTION_STACK: Transaction[] = []; diff --git a/packages/@glimmer/validator/lib/meta.ts b/packages/@glimmer/validator/lib/meta.ts index 56e30cc7be1..78c8a87e0d5 100644 --- a/packages/@glimmer/validator/lib/meta.ts +++ b/packages/@glimmer/validator/lib/meta.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { ConstantTag, UpdatableTag } from '@glimmer/interfaces'; import type { Indexable } from './utils'; @@ -22,7 +21,7 @@ export function dirtyTagFor( key: keyof T | string | symbol, meta?: TagMeta ): void { - if (DEBUG && !isObjectLike(obj)) { + if (import.meta.env?.DEV && !isObjectLike(obj)) { throw new Error(`BUG: Can't update a tag for a primitive`); } @@ -35,7 +34,7 @@ export function dirtyTagFor( let propertyTag = tags.get(key); if (propertyTag !== undefined) { - if (DEBUG) { + if (import.meta.env?.DEV) { unwrap(debug.assertTagNotConsumed)(propertyTag, obj, key); } diff --git a/packages/@glimmer/validator/lib/tracking.ts b/packages/@glimmer/validator/lib/tracking.ts index d94ae456e6b..3b8586065e9 100644 --- a/packages/@glimmer/validator/lib/tracking.ts +++ b/packages/@glimmer/validator/lib/tracking.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { Tag } from '@glimmer/interfaces'; import type { Revision } from './validators'; @@ -19,7 +18,7 @@ class Tracker { this.tags.add(tag); - if (DEBUG) { + if (import.meta.env?.DEV) { unwrap(debug.markTagAsConsumed)(tag); } @@ -61,7 +60,7 @@ export function beginTrackFrame(debuggingContext?: string | false): void { CURRENT_TRACKER = new Tracker(); - if (DEBUG) { + if (import.meta.env?.DEV) { unwrap(debug.beginTrackingTransaction)(debuggingContext); } } @@ -69,7 +68,7 @@ export function beginTrackFrame(debuggingContext?: string | false): void { export function endTrackFrame(): Tag { let current = CURRENT_TRACKER; - if (DEBUG) { + if (import.meta.env?.DEV) { if (OPEN_TRACK_FRAMES.length === 0) { throw new Error('attempted to close a tracking frame, but one was not open'); } @@ -88,7 +87,7 @@ export function beginUntrackFrame(): void { } export function endUntrackFrame(): void { - if (DEBUG && OPEN_TRACK_FRAMES.length === 0) { + if (import.meta.env?.DEV && OPEN_TRACK_FRAMES.length === 0) { throw new Error('attempted to close a tracking frame, but one was not open'); } @@ -103,7 +102,7 @@ export function resetTracking(): string | void { CURRENT_TRACKER = null; - if (DEBUG) { + if (import.meta.env?.DEV) { return unwrap(debug.resetTrackingTransaction)(); } } @@ -142,7 +141,7 @@ interface InternalCache { } export function createCache(fn: () => T, debuggingLabel?: string | false): Cache { - if (DEBUG && !(typeof fn === 'function')) { + if (import.meta.env?.DEV && !(typeof fn === 'function')) { throw new Error( `createCache() must be passed a function as its first parameter. Called with: ${String(fn)}` ); @@ -155,7 +154,7 @@ export function createCache(fn: () => T, debuggingLabel?: string | false): Ca [SNAPSHOT]: -1, }; - if (DEBUG) { + if (import.meta.env?.DEV) { cache[DEBUG_LABEL] = debuggingLabel; } @@ -201,7 +200,7 @@ function assertCache( value: Cache | InternalCache, fnName: string ): asserts value is InternalCache { - if (DEBUG && !(typeof value === 'object' && FN in value)) { + if (import.meta.env?.DEV && !(typeof value === 'object' && FN in value)) { throw new Error( `${fnName}() can only be used on an instance of a cache created with createCache(). Called with: ${String( // eslint-disable-next-line @typescript-eslint/no-base-to-string -- @fixme @@ -213,7 +212,7 @@ function assertCache( // replace this with `expect` when we can function assertTag(tag: Tag | undefined, cache: InternalCache): asserts tag is Tag { - if (DEBUG && tag === undefined) { + if (import.meta.env?.DEV && tag === undefined) { throw new Error( `isConst() can only be used on a cache once getValue() has been called at least once. Called with cache function:\n\n${String( cache[FN] diff --git a/packages/@glimmer/validator/lib/validators.ts b/packages/@glimmer/validator/lib/validators.ts index a701a133e53..b8a2b65e861 100644 --- a/packages/@glimmer/validator/lib/validators.ts +++ b/packages/@glimmer/validator/lib/validators.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { COMBINATOR_TAG_ID as ICOMBINATOR_TAG_ID, CONSTANT_TAG_ID as ICONSTANT_TAG_ID, @@ -80,7 +79,7 @@ const TYPE: TagTypeSymbol = Symbol('TAG_TYPE') as TagTypeSymbol; // this is basically a const export let ALLOW_CYCLES: WeakMap | undefined; -if (DEBUG) { +if (import.meta.env?.DEV) { ALLOW_CYCLES = new WeakMap(); } @@ -125,7 +124,7 @@ class MonomorphicTagImpl { let { lastChecked } = this; if (this.isUpdating) { - if (DEBUG && !allowsCycles(this)) { + if (import.meta.env?.DEV && !allowsCycles(this)) { throw new Error('Cycles in tags are not allowed'); } @@ -168,7 +167,7 @@ class MonomorphicTagImpl { static updateTag(this: void, _tag: UpdatableTag, _subtag: Tag) { // catch bug by non-TS users - if (DEBUG && _tag[TYPE] !== UPDATABLE_TAG_ID) { + if (import.meta.env?.DEV && _tag[TYPE] !== UPDATABLE_TAG_ID) { throw new Error('Attempted to update a tag that was not updatable'); } @@ -208,7 +207,7 @@ class MonomorphicTagImpl { disableConsumptionAssertion?: boolean ) { if ( - DEBUG && + import.meta.env?.DEV && // catch bug by non-TS users !(tag[TYPE] === UPDATABLE_TAG_ID || tag[TYPE] === DIRYTABLE_TAG_ID) @@ -216,7 +215,7 @@ class MonomorphicTagImpl { throw new Error('Attempted to dirty a tag that was not dirtyable'); } - if (DEBUG && disableConsumptionAssertion !== true) { + if (import.meta.env?.DEV && disableConsumptionAssertion !== true) { // Usually by this point, we've already asserted with better error information, // but this is our last line of defense. unwrap(debug.assertTagNotConsumed)(tag); diff --git a/packages/@glimmer/validator/test/tracking-test.ts b/packages/@glimmer/validator/test/tracking-test.ts index 1a0fc4c1dc0..7a87eff9e9d 100644 --- a/packages/@glimmer/validator/test/tracking-test.ts +++ b/packages/@glimmer/validator/test/tracking-test.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { beginTrackFrame, consumeTag, @@ -262,7 +261,7 @@ module('@glimmer/validator: tracking', () => { endTrackFrame(); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('asserts if track frame was ended without one existing', (assert) => { assert.throws( () => endTrackFrame(), @@ -398,22 +397,22 @@ module('@glimmer/validator: tracking', () => { assert.notOk(isConst(nonConstCache), 'non-constant cache returns false'); }); - if (DEBUG) { - test('createCache throws an error in import.meta.env.DEV mode if users to use with a non-function', (assert) => { + if (import.meta.env?.DEV) { + test('createCache throws an error in DEV mode if users to use with a non-function', (assert) => { assert.throws( () => createCache(123 as any), /Error: createCache\(\) must be passed a function as its first parameter. Called with: 123/u ); }); - test('getValue throws an error in import.meta.env.DEV mode if users to use with a non-cache', (assert) => { + test('getValue throws an error in DEV mode if users to use with a non-cache', (assert) => { assert.throws( () => getValue(123 as any), /Error: getValue\(\) can only be used on an instance of a cache created with createCache\(\). Called with: 123/u ); }); - test('isConst throws an error in import.meta.env.DEV mode if users attempt to check a function before it has been called', (assert) => { + test('isConst throws an error in DEV mode if users attempt to check a function before it has been called', (assert) => { let cache = createCache(() => { // do nothing; }); @@ -424,7 +423,7 @@ module('@glimmer/validator: tracking', () => { ); }); - test('isConst throws an error in import.meta.env.DEV mode if users attempt to use with a non-cache', (assert) => { + test('isConst throws an error in DEV mode if users attempt to use with a non-cache', (assert) => { assert.throws( () => isConst(123 as any), /Error: isConst\(\) can only be used on an instance of a cache created with createCache\(\). Called with: 123/u @@ -485,7 +484,7 @@ module('@glimmer/validator: tracking', () => { assert.notOk(validateTag(tag, snapshot)); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('it errors when attempting to update a value already consumed in the same transaction', (assert) => { class Foo { foo = 123; @@ -511,7 +510,7 @@ module('@glimmer/validator: tracking', () => { } }); - if (DEBUG) { + if (import.meta.env?.DEV) { module('debug', () => { test('it errors when attempting to update a value that has already been consumed in the same transaction', (assert) => { let tag = createTag(); diff --git a/packages/@glimmer/validator/test/validators-test.ts b/packages/@glimmer/validator/test/validators-test.ts index 35d17a23e7c..04badc3bfc2 100644 --- a/packages/@glimmer/validator/test/validators-test.ts +++ b/packages/@glimmer/validator/test/validators-test.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { UpdatableTag } from '@glimmer/interfaces'; import { testOverrideGlobalContext } from '@glimmer/global-context'; import { @@ -41,7 +40,7 @@ module('@glimmer/validator: validators', () => { assert.ok(validateTag(tag, snapshot)); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('it calls scheduleRevalidate', (assert) => { let originalContext = unwrap(testOverrideGlobalContext)({ scheduleRevalidate() { @@ -145,7 +144,7 @@ module('@glimmer/validator: validators', () => { assert.notOk(validateTag(tag, snapshot), 'tag is invalid after subtag is dirtied again'); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('does not allow cycles on tags that have not been marked with ALLOW_CYCLES', (assert) => { let tag = createUpdatableTag(); let subtag = createUpdatableTag(); @@ -195,7 +194,7 @@ module('@glimmer/validator: validators', () => { assert.notOk(validateTag(combined, snapshot)); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('it cannot be dirtied', (assert) => { let tag1 = createTag(); let tag2 = createTag(); @@ -225,7 +224,7 @@ module('@glimmer/validator: validators', () => { }); module('ConstantTag', () => { - if (DEBUG) { + if (import.meta.env?.DEV) { test('it cannot be dirtied', (assert) => { assert.throws( // @ts-expect-error this is an error condition @@ -263,7 +262,7 @@ module('@glimmer/validator: validators', () => { assert.notOk(validateTag(combined, snapshot)); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('it cannot be dirtied', (assert) => { assert.throws( // @ts-expect-error this is an error condition @@ -308,7 +307,7 @@ module('@glimmer/validator: validators', () => { assert.notOk(validateTag(combined, snapshot)); }); - if (DEBUG) { + if (import.meta.env?.DEV) { test('it cannot be dirtied', (assert) => { assert.throws( // @ts-expect-error this is an error condition diff --git a/packages/ember/tests/component_registration_test.js b/packages/ember/tests/component_registration_test.js index 611eb1deac5..877fff9583c 100644 --- a/packages/ember/tests/component_registration_test.js +++ b/packages/ember/tests/component_registration_test.js @@ -3,7 +3,7 @@ import Controller from '@ember/controller'; import { Component } from '@ember/-internals/glimmer'; import { compile } from 'ember-template-compiler'; import { moduleFor, ApplicationTestCase, defineComponent } from 'internal-test-helpers'; -import { DEBUG } from '@glimmer/env'; + import templateOnly from '@ember/component/template-only'; moduleFor( @@ -159,7 +159,7 @@ moduleFor( async ['@test Using name of component that does not exist'](assert) { this.addTemplate('application', `
{{#no-good}} {{/no-good}}
`); - if (DEBUG) { + if (import.meta.env?.DEV) { await assert.rejectsAssertion(this.visit('/'), /Attempted to resolve `no-good`/); } else { // Rejects with a worse error message in production diff --git a/packages/ember/tests/production_build_test.js b/packages/ember/tests/production_build_test.js index bd96c36af4a..abb080f29d8 100644 --- a/packages/ember/tests/production_build_test.js +++ b/packages/ember/tests/production_build_test.js @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { assert as emberAssert, runInDebug } from '@ember/debug'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; @@ -6,7 +5,7 @@ moduleFor( 'production builds', class extends AbstractTestCase { ['@test assert does not throw in production builds'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.expect(1); try { @@ -21,7 +20,7 @@ moduleFor( } ['@test runInDebug does not run the callback in production builds'](assert) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { let fired = false; runInDebug(() => (fired = true)); diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index 124ec7265b5..69ca8786515 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -7,7 +7,6 @@ import { moduleFor, testUnless, } from 'internal-test-helpers'; -import { DEBUG } from '@glimmer/env'; class ReExportTests extends AbstractTestCase { [`${testUnless( @@ -166,12 +165,12 @@ let allExports = [ ['_captureRenderTree', '@ember/debug', 'captureRenderTree', test11], ['ContainerDebugAdapter', '@ember/debug/container-debug-adapter', 'default', test12], ['DataAdapter', '@ember/debug/data-adapter', 'default', test13], - DEBUG + import.meta.env?.DEV ? ['_assertDestroyablesDestroyed', '@ember/destroyable', 'assertDestroyablesDestroyed', test14] : null, ['_associateDestroyableChild', '@ember/destroyable', 'associateDestroyableChild', test14], ['destroy', '@ember/destroyable', 'destroy', test14], - DEBUG + import.meta.env?.DEV ? ['_enableDestroyableTracking', '@ember/destroyable', 'enableDestroyableTracking', test14] : null, ['_isDestroyed', '@ember/destroyable', 'isDestroyed', test14], diff --git a/packages/internal-test-helpers/lib/ember-dev/assertion.ts b/packages/internal-test-helpers/lib/ember-dev/assertion.ts index 928d038e048..66392c23e3d 100644 --- a/packages/internal-test-helpers/lib/ember-dev/assertion.ts +++ b/packages/internal-test-helpers/lib/ember-dev/assertion.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import type { DebugEnv, Message } from './utils'; import { callWithStub, checkTest } from './utils'; @@ -35,7 +34,7 @@ export function setupAssertionHelpers(hooks: NestedHooks, env: DebugEnv): void { hooks.beforeEach(function (assert) { let expectAssertion: ExpectAssertionFunc = (func: () => void, expectedMessage: Message) => { - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, 'Assertions disabled in production builds.'); return; } diff --git a/packages/internal-test-helpers/lib/ember-dev/method-call-tracker.ts b/packages/internal-test-helpers/lib/ember-dev/method-call-tracker.ts index 369d1bb2ca9..8aa2f89b609 100644 --- a/packages/internal-test-helpers/lib/ember-dev/method-call-tracker.ts +++ b/packages/internal-test-helpers/lib/ember-dev/method-call-tracker.ts @@ -1,4 +1,3 @@ -import { DEBUG } from '@glimmer/env'; import { assert as emberAssert } from '@ember/debug'; import type { DebugEnv, DebugFunction, DebugFunctionOptions } from './utils'; import { checkTest } from './utils'; @@ -82,7 +81,7 @@ export default class MethodCallTracker { return; } - if (!DEBUG) { + if (!import.meta.env?.DEV) { assert.ok(true, `calls to Ember.${methodName} disabled in production builds.`); return; } diff --git a/packages/internal-test-helpers/lib/ember-dev/setup-qunit.ts b/packages/internal-test-helpers/lib/ember-dev/setup-qunit.ts index 78423b64470..e1013723646 100644 --- a/packages/internal-test-helpers/lib/ember-dev/setup-qunit.ts +++ b/packages/internal-test-helpers/lib/ember-dev/setup-qunit.ts @@ -1,5 +1,5 @@ import { getOnerror, setOnerror } from '@ember/-internals/error-handling'; -import { DEBUG } from '@glimmer/env'; + import { resetTracking } from '@glimmer/validator'; declare global { @@ -52,7 +52,7 @@ export default function setupQUnit() { expected?: string | RegExp, message?: string ) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { QUnit.assert.ok(true, 'Assertions disabled in production builds.'); return; } @@ -65,7 +65,7 @@ export default function setupQUnit() { expected?: string | RegExp, message?: string ) { - if (!DEBUG) { + if (!import.meta.env?.DEV) { QUnit.assert.ok(true, 'Assertions disabled in production builds.'); return promise; diff --git a/packages/internal-test-helpers/lib/module-for.ts b/packages/internal-test-helpers/lib/module-for.ts index b091ef50b98..6a431ef5f16 100644 --- a/packages/internal-test-helpers/lib/module-for.ts +++ b/packages/internal-test-helpers/lib/module-for.ts @@ -1,7 +1,7 @@ /* globals URLSearchParams */ import { isEnabled } from '@ember/canary-features'; import { assertDestroyablesDestroyed, enableDestroyableTracking } from '@glimmer/destroyable'; -import { DEBUG } from '@glimmer/env'; + import { all } from 'rsvp'; import type { Generator, Mixin } from './apply-mixins'; import applyMixins from './apply-mixins'; @@ -78,7 +78,7 @@ export default function moduleFor( function afterEachFinally() { unsetContext(); - if (DEBUG && ASSERT_DESTROYABLES) { + if (import.meta.env?.DEV && ASSERT_DESTROYABLES) { assertDestroyablesDestroyed!(); } } @@ -89,7 +89,7 @@ export function setupTestClass( ...mixins: Mixin[] ) { hooks.beforeEach(function (this: TestContext, assert: QUnit['assert']) { - if (DEBUG && ASSERT_DESTROYABLES) { + if (import.meta.env?.DEV && ASSERT_DESTROYABLES) { enableDestroyableTracking!(); } diff --git a/rollup.config.mjs b/rollup.config.mjs index 6885fae4533..cc8957308a9 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -6,6 +6,7 @@ import glob from 'glob'; import * as resolveExports from 'resolve.exports'; import { babel } from '@rollup/plugin-babel'; import sharedBabelConfig from './babel.config.mjs'; +import { importMetaRemoval } from './broccoli/import-meta.js'; // eslint-disable-next-line no-redeclare const require = createRequire(import.meta.url); @@ -13,7 +14,6 @@ const { PackageCache, packageName } = require('@embroider/shared-internals'); const projectRoot = dirname(fileURLToPath(import.meta.url)); const packageCache = PackageCache.shared('ember-source', projectRoot); const { buildInfo } = require('./broccoli/build-info'); -const buildDebugMacroPlugin = require('./broccoli/build-debug-macro-plugin'); const canaryFeatures = require('./broccoli/canary-features'); const testDependencies = [ @@ -84,11 +84,7 @@ function esmTemplateCompiler() { function sharedESMConfig({ input, debugMacrosMode }) { let babelConfig = { ...sharedBabelConfig }; - babelConfig.plugins = [ - ...babelConfig.plugins, - buildDebugMacroPlugin(debugMacrosMode), - canaryFeatures(), - ]; + babelConfig.plugins = [...babelConfig.plugins, canaryFeatures()]; return { onLog: handleRollupWarnings, @@ -101,6 +97,7 @@ function sharedESMConfig({ input, debugMacrosMode }) { chunkFileNames: 'packages/shared-chunks/[name]-[hash].js', }, plugins: [ + importMetaRemoval(debugMacrosMode), babel({ babelHelpers: 'bundled', extensions: ['.js', '.ts'], @@ -148,7 +145,7 @@ function renameEntrypoints(entrypoints, fn) { function legacyBundleConfig(input, output, { isDeveloping, isExternal }) { let babelConfig = { ...sharedBabelConfig }; - babelConfig.plugins = [...babelConfig.plugins, buildDebugMacroPlugin(isDeveloping)]; + babelConfig.plugins = [...babelConfig.plugins]; return { input, @@ -174,6 +171,7 @@ function legacyBundleConfig(input, output, { isDeveloping, isExternal }) { }, onLog: handleRollupWarnings, plugins: [ + importMetaRemoval(isDeveloping), amdDefineSupport(), ...(isDeveloping ? [concatenateAMDEntrypoints()] : []), babel({ diff --git a/vite.config.mjs b/vite.config.mjs index 57b0ca0b314..3e4e5442388 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -12,6 +12,7 @@ import { hiddenDependencies, } from './rollup.config.mjs'; import { templateTag } from '@embroider/vite'; +import { importMetaRemoval } from './broccoli/import-meta.js'; const require = createRequire(import.meta.url); const projectRoot = dirname(fileURLToPath(import.meta.url)); @@ -34,6 +35,7 @@ export default defineConfig(({ mode }) => { return { plugins: [ templateTag(), + importMetaRemoval(mode === 'development'), babel({ babelHelpers: 'bundled', extensions: ['.js', '.ts', '.gjs', '.gts'],