Skip to content

Commit

Permalink
Rename Option to Nullable to align with glimmer-vm terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Nov 14, 2023
1 parent 2120346 commit 09a7648
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@ember/-internals/owner';
import { enumerableSymbol, guidFor } from '@ember/-internals/utils';
import { addChildView, setElementView, setViewElement } from '@ember/-internals/views';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { assert, debugFreeze } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class CurlyComponentManager
return this.templateFor(bucket.component);
}

getTagName(state: ComponentStateBucket): Option<string> {
getTagName(state: ComponentStateBucket): Nullable<string> {
let { component, hasWrappedElement } = state;

if (!hasWrappedElement) {
Expand All @@ -168,7 +168,7 @@ export default class CurlyComponentManager
return CURLY_CAPABILITIES;
}

prepareArgs(ComponentClass: ComponentFactory, args: VMArguments): Option<PreparedArguments> {
prepareArgs(ComponentClass: ComponentFactory, args: VMArguments): Nullable<PreparedArguments> {
if (args.named.has('__ARGS__')) {
assert(
'[BUG] cannot pass both __ARGS__ and positional arguments',
Expand Down Expand Up @@ -467,7 +467,7 @@ export default class CurlyComponentManager
}
}

getDestroyable(bucket: ComponentStateBucket): Option<Destroyable> {
getDestroyable(bucket: ComponentStateBucket): Nullable<Destroyable> {
return bucket;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
WithDynamicLayout,
WithSubOwner,
} from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createConstRef, valueForRef } from '@glimmer/reference';
Expand Down Expand Up @@ -149,7 +149,7 @@ class MountManager
return self;
}

getDestroyable(bucket: EngineState): Option<Destroyable> {
getDestroyable(bucket: EngineState): Nullable<Destroyable> {
return bucket.engine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
WithCustomDebugRenderTree,
WithDynamicTagName,
} from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createConstRef, valueForRef } from '@glimmer/reference';
Expand Down Expand Up @@ -179,7 +179,7 @@ class OutletComponentManager

didUpdateLayout() {}

getDestroyable(): Option<Destroyable> {
getDestroyable(): Nullable<Destroyable> {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
Owner,
VMArguments,
} from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { capabilityFlagsFrom } from '@glimmer/manager';
import { CONSTANT_TAG, consumeTag } from '@glimmer/validator';
import type Component from '../component';
Expand All @@ -32,7 +32,7 @@ class RootComponentManager extends CurlyComponentManager {
create(
_owner: Owner,
_state: unknown,
_args: Option<VMArguments>,
_args: Nullable<VMArguments>,
{ isInteractive }: Environment,
dynamicScope: DynamicScope
) {
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { action } from '@ember/object';
import { service } from '@ember/service';
import { DEBUG } from '@glimmer/env';
import type { Maybe } from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { consumeTag, createCache, getValue, tagFor, untrack } from '@glimmer/validator';
import type { Transition } from 'router_js';
import LinkToTemplate from '../templates/link-to';
Expand All @@ -32,7 +32,7 @@ function isPresent<T>(value: Maybe<T>): value is T {

interface QueryParams {
isQueryParams: true;
values: Option<{}>;
values: Nullable<{}>;
}

function isQueryParams(value: unknown): value is QueryParams {
Expand Down Expand Up @@ -474,7 +474,7 @@ class _LinkTo extends InternalComponent {
return this.isActiveForState(this.routing.currentState as Maybe<RouterState>);
}

private get willBeActive(): Option<boolean> {
private get willBeActive(): Nullable<boolean> {
let current = this.routing.currentState;
let target = this.routing.targetState;

Expand Down Expand Up @@ -586,7 +586,7 @@ class _LinkTo extends InternalComponent {

let { prototype } = _LinkTo;

let descriptorFor = (target: object, property: string): Option<PropertyDescriptor> => {
let descriptorFor = (target: object, property: string): Nullable<PropertyDescriptor> => {
if (target) {
return (
Object.getOwnPropertyDescriptor(target, property) ||
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
} from '@glimmer/interfaces';

import { CurriedType } from '@glimmer/vm';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import { programCompilationContext } from '@glimmer/opcode-compiler';
import { artifacts, RuntimeOpImpl } from '@glimmer/program';
import type { Reference } from '@glimmer/reference';
Expand Down Expand Up @@ -55,7 +55,7 @@ import OutletView from './views/outlet';
export type IBuilder = (env: Environment, cursor: Cursor) => ElementBuilder;

export interface View {
parentView: Option<View>;
parentView: Nullable<View>;
renderer: Renderer;
tagName: string | null;
elementId: string | null;
Expand Down Expand Up @@ -464,7 +464,7 @@ export class Renderer {
this._clearAllRoots();
}

getElement(view: View): Option<Element> {
getElement(view: View): Nullable<Element> {
if (this._isInteractive) {
return getViewElement(view);
} else {
Expand Down
14 changes: 7 additions & 7 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
Template,
TemplateFactory,
} from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import {
getComponentTemplate,
getInternalComponentManager,
Expand Down Expand Up @@ -55,7 +55,7 @@ function instrumentationPayload(name: string) {
function componentFor(
name: string,
owner: InternalOwner
): Option<InternalFactory<object> | object> {
): Nullable<InternalFactory<object> | object> {
let fullName = `component:${name}` as const;
return owner.factoryFor(fullName) || null;
}
Expand All @@ -64,7 +64,7 @@ function layoutFor(
name: string,
owner: InternalOwner,
options?: RegisterOptions
): Option<Template> {
): Nullable<Template> {
let templateFullName = `template:components/${name}` as const;

return (owner.lookup(templateFullName, options) as Template) || null;
Expand All @@ -88,7 +88,7 @@ function lookupComponentPair(
owner: InternalOwner,
name: string,
options?: RegisterOptions
): Option<LookupResult> {
): Nullable<LookupResult> {
let component = componentFor(name, owner);

if (isFactory(component) && component.class) {
Expand Down Expand Up @@ -167,7 +167,7 @@ export default class ResolverImpl
return null;
}

lookupHelper(name: string, owner: InternalOwner): Option<HelperDefinitionState> {
lookupHelper(name: string, owner: InternalOwner): Nullable<HelperDefinitionState> {
assert(
`You attempted to overwrite the built-in helper "${name}" which is not allowed. Please rename the helper.`,
!(BUILTIN_HELPERS[name] && owner.hasRegistration(`helper:${name}`))
Expand Down Expand Up @@ -216,7 +216,7 @@ export default class ResolverImpl
return BUILTIN_KEYWORD_HELPERS[name] ?? null;
}

lookupModifier(name: string, owner: InternalOwner): Option<ModifierDefinitionState> {
lookupModifier(name: string, owner: InternalOwner): Nullable<ModifierDefinitionState> {
let builtin = BUILTIN_MODIFIERS[name];

if (builtin !== undefined) {
Expand Down Expand Up @@ -271,7 +271,7 @@ export default class ResolverImpl

let finalizer = _instrumentStart('render.getComponentDefinition', instrumentationPayload, name);

let definition: Option<ResolvedComponentDefinition> = null;
let definition: Nullable<ResolvedComponentDefinition> = null;

if (pair.component === null) {
if (ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/syntax/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { InternalOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import type { CapturedArguments } from '@glimmer/interfaces';
import { CurriedType } from '@glimmer/vm';
import type { Reference } from '@glimmer/reference';
Expand Down Expand Up @@ -57,7 +57,7 @@ import { internalHelper } from '../helpers/internal-helper';
export const mountHelper = internalHelper(
(args: CapturedArguments, owner?: InternalOwner): Reference<CurriedValue | null> => {
assert('{{mount}} must be used within a component that has an owner', owner);
let nameRef = args.positional[0] as Reference<Option<string>>;
let nameRef = args.positional[0] as Reference<Nullable<string>>;
let captured: CapturedArguments | null;

assert(
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/syntax/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Core, PresentArray } from '@glimmer/interfaces';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';

export function hashToArgs(hash: Option<Core.Hash>): Option<Core.Hash> {
export function hashToArgs(hash: Nullable<Core.Hash>): Nullable<Core.Hash> {
if (hash === null) return null;
let names = hash[0].map((key) => `@${key}`);
return [names as PresentArray<string>, hash[1]];
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/utils/iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { objectAt } from '@ember/-internals/metal';
import type EmberArray from '@ember/array';
import { isEmberArray } from '@ember/array/-internals';
import { isObject } from '@ember/-internals/utils';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import type { IteratorDelegate } from '@glimmer/reference';
import { consumeTag, isTracking, tagFor } from '@glimmer/validator';
import { EachInWrapper } from '../helpers/each-in';
import type { NativeArray } from '@ember/array';

export default function toIterator(iterable: unknown): Option<IteratorDelegate> {
export default function toIterator(iterable: unknown): Nullable<IteratorDelegate> {
if (iterable instanceof EachInWrapper) {
return toEachInIterator(iterable.inner);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/-internals/utility-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export class Opaque<Data> {
private declare [Data]: Data;
}

export type Option<T> = T | null;
export type Nullable<T> = T | null;
8 changes: 4 additions & 4 deletions packages/@ember/-internals/views/lib/system/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { guidFor } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import type { Dict } from '@glimmer/interfaces';

import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';

/**
@module ember
Expand Down Expand Up @@ -72,7 +72,7 @@ export function getViewId(view: View): string {
const ELEMENT_VIEW: WeakMap<Element, View> = new WeakMap();
const VIEW_ELEMENT: WeakMap<View, Element> = new WeakMap();

export function getElementView(element: Element): Option<View> {
export function getElementView(element: Element): Nullable<View> {
return ELEMENT_VIEW.get(element) || null;
}

Expand All @@ -81,7 +81,7 @@ export function getElementView(element: Element): Option<View> {
@method getViewElement
@param {Ember.View} view
*/
export function getViewElement(view: View): Option<Element> {
export function getViewElement(view: View): Nullable<Element> {
return VIEW_ELEMENT.get(view) || null;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ export function contains(a: Node, b: Node): boolean {
return a.contains(b);
}

let current: Option<Node> = b.parentNode;
let current: Nullable<Node> = b.parentNode;

while (current && (current = current.parentNode)) {
if (current === a) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/routing/lib/dsl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { InternalFactory } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import type { MatchCallback } from 'route-recognizer';
import type { EngineInfo, EngineRouteInfo } from './engines';

Expand Down Expand Up @@ -67,7 +67,7 @@ export default class DSLImpl implements DSL {
route(name: string, options: RouteOptions, callback: DSLCallback): void;
route(name: string, _options?: RouteOptions | DSLCallback, _callback?: DSLCallback): void {
let options: RouteOptions;
let callback: Option<DSLCallback> = null;
let callback: Nullable<DSLCallback> = null;

let dummyErrorRoute = `/_unused_dummy_error_path_route_${name}/:error`;
if (isCallback(_options)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { precompile } from '@glimmer/compiler';
import type { Option } from '@ember/-internals/utility-types';
import type { Nullable } from '@ember/-internals/utility-types';
import type { AST, ASTPlugin } from '@glimmer/syntax';
import { AbstractTestCase } from 'internal-test-helpers';
import { compileOptions } from '../../index';
Expand All @@ -11,7 +11,7 @@ export default abstract class extends AbstractTestCase {
}

function ast(template: string): AST.Program {
let program: Option<AST.Program> = null;
let program: Nullable<AST.Program> = null;

function extractProgram(): ASTPlugin {
return {
Expand Down

0 comments on commit 09a7648

Please sign in to comment.