Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the VM in order to upstream built-ins #19317

Merged
merged 1 commit into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@
},
"devDependencies": {
"@babel/preset-env": "^7.9.5",
"@glimmer/compiler": "0.72.0",
"@glimmer/compiler": "0.73.0",
"@glimmer/env": "^0.1.7",
"@glimmer/global-context": "0.72.0",
"@glimmer/interfaces": "0.72.0",
"@glimmer/manager": "0.72.0",
"@glimmer/destroyable": "0.72.0",
"@glimmer/owner": "0.72.0",
"@glimmer/node": "0.72.0",
"@glimmer/opcode-compiler": "0.72.0",
"@glimmer/program": "0.72.0",
"@glimmer/reference": "0.72.0",
"@glimmer/runtime": "0.72.0",
"@glimmer/validator": "0.72.0",
"@glimmer/global-context": "0.73.0",
"@glimmer/interfaces": "0.73.0",
"@glimmer/manager": "0.73.0",
"@glimmer/destroyable": "0.73.0",
"@glimmer/owner": "0.73.0",
"@glimmer/node": "0.73.0",
"@glimmer/opcode-compiler": "0.73.0",
"@glimmer/program": "0.73.0",
"@glimmer/reference": "0.73.0",
"@glimmer/runtime": "0.73.0",
"@glimmer/validator": "0.73.0",
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.9.1",
"@types/rsvp": "^4.0.3",
Expand Down
7 changes: 0 additions & 7 deletions packages/@ember/-internals/glimmer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,6 @@ export {
export { setupEngineRegistry, setupApplicationRegistry } from './lib/setup-registry';
export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './lib/dom';

export { default as array } from './lib/helpers/array';
export { default as hash } from './lib/helpers/hash';
export { default as concat } from './lib/helpers/concat';
export { default as get } from './lib/helpers/get';
export { default as fn } from './lib/helpers/fn';
export { default as on } from './lib/modifiers/on';

// needed for test
// TODO just test these through public API
// a lot of these are testing how a problem was solved
Expand Down
5 changes: 3 additions & 2 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from '@ember/-internals/environment';
import { _getProp, get, set } from '@ember/-internals/metal';
import { _getProp, _setProp, get, set } from '@ember/-internals/metal';
import { Owner } from '@ember/-internals/owner';
import { getDebugName } from '@ember/-internals/utils';
import { constructStyleDeprecationMessage } from '@ember/-internals/views';
Expand All @@ -26,8 +26,9 @@ setGlobalContext({
toIterator,

getProp: _getProp,
setProp: set,
setProp: _setProp,
getPath: get,
setPath: set,

scheduleDestroy(destroyable, destructor) {
schedule('actions', null, destructor, destroyable);
Expand Down
13 changes: 0 additions & 13 deletions packages/@ember/-internals/glimmer/lib/helpers/array.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { VMArguments } from '@glimmer/interfaces';
import { createComputeRef, Reference } from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import { internalHelper } from './internal-helper';

/**
@module ember
*/
Expand Down Expand Up @@ -42,11 +37,3 @@ import { internalHelper } from './internal-helper';
@since 3.8.0
@public
*/

export default internalHelper(
(args: VMArguments): Reference<unknown[]> => {
let captured = args.positional.capture();

return createComputeRef(() => reifyPositional(captured), null, 'array');
}
);
25 changes: 0 additions & 25 deletions packages/@ember/-internals/glimmer/lib/helpers/concat.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import { VMArguments } from '@glimmer/interfaces';
import { createComputeRef } from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import { internalHelper } from './internal-helper';

const isEmpty = (value: unknown): boolean => {
return value === null || value === undefined || typeof (value as object).toString !== 'function';
};

const normalizeTextValue = (value: unknown): string => {
if (isEmpty(value)) {
return '';
}
return String(value);
};

/**
@module ember
*/
Expand All @@ -40,12 +24,3 @@ const normalizeTextValue = (value: unknown): string => {
@for Ember.Templates.helpers
@since 1.13.0
*/
export default internalHelper((args: VMArguments) => {
let captured = args.positional.capture();

return createComputeRef(
() => reifyPositional(captured).map(normalizeTextValue).join(''),
null,
'concat'
);
});
50 changes: 0 additions & 50 deletions packages/@ember/-internals/glimmer/lib/helpers/fn.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { VMArguments } from '@glimmer/interfaces';
import {
createComputeRef,
isInvokableRef,
Reference,
updateRef,
valueForRef,
} from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import buildUntouchableThis from '../utils/untouchable-this';
import { internalHelper } from './internal-helper';

const context = buildUntouchableThis('`fn` helper');

/**
@module ember
*/
Expand Down Expand Up @@ -85,37 +69,3 @@ const context = buildUntouchableThis('`fn` helper');
@public
@since 3.11.0
*/
export default internalHelper((args: VMArguments) => {
let positional = args.positional.capture();
let callbackRef = positional[0];

if (DEBUG) assertCallbackIsFn(callbackRef);

return createComputeRef(
() => {
return (...invocationArgs: unknown[]) => {
let [fn, ...args] = reifyPositional(positional);

if (DEBUG) assertCallbackIsFn(callbackRef);

if (isInvokableRef(callbackRef)) {
let value = args.length > 0 ? args[0] : invocationArgs[0];
return updateRef(callbackRef, value);
} else {
return (fn as Function).call(context, ...args, ...invocationArgs);
}
};
},
null,
'fn'
);
});

function assertCallbackIsFn(callbackRef: Reference) {
assert(
`You must pass a function as the \`fn\` helpers first argument, you passed ${
callbackRef ? valueForRef(callbackRef) : callbackRef
}. While rendering:\n\n${callbackRef?.debugLabel}`,
callbackRef && (isInvokableRef(callbackRef) || typeof valueForRef(callbackRef) === 'function')
);
}
50 changes: 0 additions & 50 deletions packages/@ember/-internals/glimmer/lib/helpers/get.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import { get, set } from '@ember/-internals/metal';
import { isObject } from '@ember/-internals/utils';
import { VMArguments } from '@glimmer/interfaces';
import {
childRefFor,
childRefFromParts,
createComputeRef,
isConstRef,
NULL_REFERENCE,
valueForRef,
} from '@glimmer/reference';
import { internalHelper } from './internal-helper';

/**
@module ember
*/
Expand Down Expand Up @@ -95,40 +82,3 @@ import { internalHelper } from './internal-helper';
@for Ember.Templates.helpers
@since 2.1.0
*/
export default internalHelper((args: VMArguments) => {
let sourceRef = args.positional.at(0);
let pathRef = args.positional.at(1);

if (isConstRef(pathRef)) {
// Since the path is constant, we can create a normal chain of property
// references. The source reference will update like normal, and all of the
// child references will update accordingly.
let path = valueForRef(pathRef);

if (path === undefined || path === null || path === '') {
return NULL_REFERENCE;
} else if (typeof path === 'string' && path.indexOf('.') > -1) {
return childRefFromParts(sourceRef, path.split('.'));
} else {
return childRefFor(sourceRef, String(path));
}
} else {
return createComputeRef(
() => {
let source = valueForRef(sourceRef);

if (isObject(source)) {
return get(source, String(valueForRef(pathRef)));
}
},
(value) => {
let source = valueForRef(sourceRef);

if (isObject(source)) {
return set(source, String(valueForRef(pathRef)), value);
}
},
'get'
);
}
});
12 changes: 0 additions & 12 deletions packages/@ember/-internals/glimmer/lib/helpers/hash.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { Dict, VMArguments } from '@glimmer/interfaces';
import { createComputeRef, Reference } from '@glimmer/reference';
import { reifyNamed } from '@glimmer/runtime';
import { internalHelper } from './internal-helper';

/**
@module ember
*/
Expand Down Expand Up @@ -45,10 +40,3 @@ import { internalHelper } from './internal-helper';
@since 2.3.0
@public
*/
export default internalHelper(
(args: VMArguments): Reference<Dict<unknown>> => {
let positional = args.named.capture();

return createComputeRef(() => reifyNamed(positional), null, 'hash');
}
);
50 changes: 0 additions & 50 deletions packages/@ember/-internals/glimmer/lib/helpers/if-unless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
@module ember
*/

import { assert } from '@ember/debug';
import { toBool } from '@glimmer/global-context';
import { VMArguments } from '@glimmer/interfaces';
import { createComputeRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';

/**
The `if` helper allows you to conditionally render one of two branches,
depending on the "truthiness" of a property.
Expand Down Expand Up @@ -99,28 +93,6 @@ import { internalHelper } from './internal-helper';
@for Ember.Templates.helpers
@public
*/
export const inlineIf = internalHelper((args: VMArguments) => {
let positional = args.positional.capture();

return createComputeRef(
() => {
assert(
'The inline form of the `if` helper expects two or three arguments, e.g. `{{if trialExpired "Expired" expiryDate}}`.',
positional.length === 3 || positional.length === 2
);

let [condition, truthyValue, falsyValue] = positional;

if (toBool(valueForRef(condition)) === true) {
return valueForRef(truthyValue);
} else {
return falsyValue !== undefined ? valueForRef(falsyValue) : undefined;
}
},
null,
'if'
);
});

/**
The `unless` helper is the inverse of the `if` helper. It displays if a value
Expand Down Expand Up @@ -207,25 +179,3 @@ export const inlineIf = internalHelper((args: VMArguments) => {
@for Ember.Templates.helpers
@public
*/
export const inlineUnless = internalHelper((args: VMArguments) => {
let positional = args.positional.capture();

return createComputeRef(
() => {
assert(
'The inline form of the `unless` helper expects two or three arguments, e.g. `{{unless isFirstLogin "Welcome back!"}}`.',
positional.length === 3 || positional.length === 2
);

let [condition, falsyValue, truthyValue] = positional;

if (toBool(valueForRef(condition)) === true) {
return truthyValue !== undefined ? valueForRef(truthyValue) : undefined;
} else {
return valueForRef(falsyValue);
}
},
null,
'unless'
);
});
14 changes: 0 additions & 14 deletions packages/@ember/-internals/glimmer/lib/helpers/log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { VMArguments } from '@glimmer/interfaces';
import { createComputeRef } from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import { internalHelper } from './internal-helper';

/**
@module ember
*/
Expand All @@ -20,12 +15,3 @@ import { internalHelper } from './internal-helper';
@param {Array} params
@public
*/
export default internalHelper((args: VMArguments) => {
let positional = args.positional.capture();

return createComputeRef(() => {
/* eslint-disable no-console */
console.log(...reifyPositional(positional));
/* eslint-enable no-console */
});
});
Loading