Skip to content

Commit

Permalink
Upgrade Glimmer and TypeScript
Browse files Browse the repository at this point in the history
@glimmer/* 0.37.1 -> 0.38.1
typescript 3.0.1 -> 3.2.4

(cherry picked from commit bfa97c8)
  • Loading branch information
chancancode committed Apr 8, 2019
1 parent fccbf36 commit da2307a
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 215 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@
"@babel/plugin-transform-shorthand-properties": "^7.2.0",
"@babel/plugin-transform-spread": "^7.2.2",
"@babel/plugin-transform-template-literals": "^7.2.0",
"@glimmer/compiler": "^0.37.1",
"@glimmer/compiler": "^0.38.1",
"@glimmer/env": "^0.1.7",
"@glimmer/interfaces": "^0.37.1",
"@glimmer/node": "^0.37.1",
"@glimmer/opcode-compiler": "^0.37.1",
"@glimmer/program": "^0.37.1",
"@glimmer/reference": "^0.37.1",
"@glimmer/runtime": "^0.37.1",
"@glimmer/interfaces": "^0.38.1",
"@glimmer/node": "^0.38.1",
"@glimmer/opcode-compiler": "^0.38.1",
"@glimmer/program": "^0.38.1",
"@glimmer/reference": "^0.38.1",
"@glimmer/runtime": "^0.38.1",
"@types/qunit": "^2.5.4",
"@types/rsvp": "^4.0.2",
"auto-dist-tag": "^1.0.0",
Expand All @@ -115,7 +115,7 @@
"broccoli-rollup": "^2.1.1",
"broccoli-source": "^1.1.0",
"broccoli-string-replace": "^0.1.2",
"broccoli-typescript-compiler": "^4.0.1",
"broccoli-typescript-compiler": "^4.1.0",
"broccoli-uglify-sourcemap": "^2.2.0",
"common-tags": "^1.8.0",
"core-js": "^2.6.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/-internals/glimmer/lib/helpers/loc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ import { helper } from '../helper';
@public
*/
export default helper(function(params) {
return loc.apply(null, params);
return loc.apply(null, params as any /* let the other side handle errors */);
});
54 changes: 48 additions & 6 deletions packages/@ember/-internals/glimmer/lib/utils/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ConditionalReference as GlimmerConditionalReference,
PrimitiveReference,
} from '@glimmer/runtime';
import { Option } from '@glimmer/util';
import { Option, unreachable } from '@glimmer/util';
import { HelperFunction, HelperInstance, RECOMPUTE_TAG } from '../helper';
import emberToBool from './to-bool';

Expand Down Expand Up @@ -481,14 +481,56 @@ export function referenceFromParts(
return reference;
}

type Primitive = undefined | null | boolean | number | string;

function isObject(value: Opaque): value is object {
return value !== null && typeof value === 'object';
}

function isFunction(value: Opaque): value is Function {
return typeof value === 'function';
}

function isPrimitive(value: Opaque): value is Primitive {
if (DEBUG) {
let type = typeof value;
return (
value === undefined ||
value === null ||
type === 'boolean' ||
type === 'number' ||
type === 'string'
);
} else {
return true;
}
}

export function valueToRef<T = Opaque>(value: T, bound = true): VersionedPathReference<T> {
if (value !== null && typeof value === 'object') {
if (isObject(value)) {
// root of interop with ember objects
return bound ? new RootReference(value) : new UnboundReference(value);
}
// ember doesn't do observing with functions
if (typeof value === 'function') {
} else if (isFunction(value)) {
// ember doesn't do observing with functions
return new UnboundReference(value);
} else if (isPrimitive(value)) {
return PrimitiveReference.create(value);
} else if (DEBUG) {
let type = typeof value;
let output: Option<string>;

try {
output = String(value);
} catch (e) {
output = null;
}

if (output) {
throw unreachable(`[BUG] Unexpected ${type} (${output})`);
} else {
throw unreachable(`[BUG] Unexpected ${type}`);
}
} else {
throw unreachable();
}
return PrimitiveReference.create(value);
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { isSerializationFirstNode } from '@glimmer/util';
export { isSerializationFirstNode } from '@glimmer/runtime';
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { tagForProperty, update } from './tags';
import { getCurrentTracker, setCurrentTracker } from './tracked';

export type ComputedPropertyGetter = (keyName: string) => any;
export type ComputedPropertySetter = (keyName: string, value: any) => any;
export type ComputedPropertySetter = (keyName: string, value: any, cachedValue?: any) => any;

export interface ComputedPropertyGetterAndSetter {
get?: ComputedPropertyGetter;
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/metal/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ if (DEBUG) {

let runner = new TransactionRunner();

runInTransaction = runner.runInTransaction.bind(runner);
didRender = runner.didRender.bind(runner);
assertNotRendered = runner.assertNotRendered.bind(runner);
runInTransaction = (...args) => runner.runInTransaction(...args);
didRender = (...args) => runner.didRender(...args);
assertNotRendered = (...args) => runner.assertNotRendered(...args);
} else {
// in production do nothing to detect reflushes
runInTransaction = <T extends object, K extends MethodKey<T>>(context: T, methodName: K) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function detectImplementation(options: DetectionOptions) {
if (currentPath === historyPath) {
implementation = 'history';
} else if (currentPath.substr(0, 2) === '/#') {
history!.replaceState({ path: historyPath }, undefined, historyPath);
history!.replaceState({ path: historyPath }, '', historyPath);
implementation = 'history';
} else {
cancelRouterSetup = true;
Expand Down
94 changes: 68 additions & 26 deletions packages/@ember/-internals/routing/lib/system/dsl.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,96 @@
import { Factory } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { assign } from '@ember/polyfills';
import { Option } from '@glimmer/interfaces';
import { MatchCallback } from 'route-recognizer';
import { EngineInfo, EngineRouteInfo } from './engines';

let uuid = 0;

interface DSLOptions {
enableLoadingSubstates: boolean;
overrideNameAssertion?: boolean;
engineInfo?: EngineInfo;
addRouteForEngine(name: string, routeOptions: EngineRouteInfo): void;
resolveRouteMap(name: string): Factory<any, any>;
path?: string;
}

interface RouteOptions {
export interface RouteOptions {
path?: string;
resetNamespace?: boolean;
serialize?: any;
overrideNameAssertion?: boolean;
}

interface MountOptions {
export interface MountOptions {
path?: string;
as?: string;
resetNamespace?: boolean;
}

class DSL {
export interface DSLCallback {
(this: DSL): void;
}

export interface DSL {
route(name: string): void;
route(name: string, callback: DSLCallback): void;
route(name: string, options: RouteOptions): void;
route(name: string, options: RouteOptions, callback: DSLCallback): void;

mount(name: string): void;
mount(name: string, options: MountOptions): void;
}

function isCallback(value?: RouteOptions | DSLCallback): value is DSLCallback {
return typeof value === 'function';
}

function isOptions(value?: RouteOptions | DSLCallback): value is RouteOptions {
return value !== null && typeof value === 'object';
}
export interface DSLImplOptions {
enableLoadingSubstates: boolean;
overrideNameAssertion?: boolean;
engineInfo?: EngineInfo;
addRouteForEngine(name: string, routeOptions: EngineRouteInfo): void;
resolveRouteMap(name: string): Factory<any, any>;
path?: string;
}

export default class DSLImpl implements DSL {
parent: string | null;
matches: any[];
enableLoadingSubstates: boolean;
explicitIndex = false;
options: DSLOptions;
options: DSLImplOptions;

constructor(name: string | null = null, options: DSLOptions) {
constructor(name: string | null = null, options: DSLImplOptions) {
this.parent = name;
this.enableLoadingSubstates = Boolean(options && options.enableLoadingSubstates);
this.matches = [];
this.options = options;
}

route(name: string, options: any = {}, callback?: MatchCallback) {
/* eslint-disable no-dupe-class-members */
route(name: string): void;
route(name: string, callback: DSLCallback): void;
route(name: string, options: RouteOptions): void;
route(name: string, options: RouteOptions, callback: DSLCallback): void;
route(name: string, _options?: RouteOptions | DSLCallback, _callback?: DSLCallback) {
let options: RouteOptions;
let callback: Option<DSLCallback> = null;

let dummyErrorRoute = `/_unused_dummy_error_path_route_${name}/:error`;
if (arguments.length === 2 && typeof options === 'function') {
callback = options;
if (isCallback(_options)) {
assert('Unexpected arguments', arguments.length === 2);
options = {};
callback = _options;
} else if (isCallback(_callback)) {
assert('Unexpected arguments', arguments.length === 3);
assert('Unexpected arguments', isOptions(_options));
options = _options as RouteOptions;
callback = _callback;
} else {
options = _options || {};
}

assert(
`'${name}' cannot be used as a route name.`,
(() => {
if (options!.overrideNameAssertion === true) {
if (options.overrideNameAssertion === true) {
return true;
}

Expand All @@ -77,7 +115,7 @@ class DSL {

if (callback) {
let fullName = getFullName(this, name, options.resetNamespace);
let dsl = new DSL(fullName, this.options);
let dsl = new DSLImpl(fullName, this.options);

createRoute(dsl, 'loading');
createRoute(dsl, 'error', { path: dummyErrorRoute });
Expand All @@ -89,6 +127,7 @@ class DSL {
createRoute(this, name, options);
}
}
/* eslint-enable no-dupe-class-members */

push(url: string, name: string, callback?: MatchCallback, serialize?: any) {
let parts = name.split('.');
Expand Down Expand Up @@ -129,7 +168,7 @@ class DSL {
};
}

mount(_name: string, options: MountOptions = {}) {
mount(_name: string, options: Partial<MountOptions> = {}) {
let engineRouteMap = this.options.resolveRouteMap(_name);
let name = _name;

Expand Down Expand Up @@ -163,7 +202,7 @@ class DSL {
}

let optionsForChild = assign({ engineInfo }, this.options);
let childDSL = new DSL(fullName, optionsForChild);
let childDSL = new DSLImpl(fullName, optionsForChild);

createRoute(childDSL, 'loading');
createRoute(childDSL, 'error', { path: dummyErrorRoute });
Expand Down Expand Up @@ -207,21 +246,24 @@ class DSL {
}
}

export default DSL;

function canNest(dsl: DSL) {
function canNest(dsl: DSLImpl) {
return dsl.parent !== 'application';
}

function getFullName(dsl: DSL, name: string, resetNamespace?: boolean) {
function getFullName(dsl: DSLImpl, name: string, resetNamespace?: boolean) {
if (canNest(dsl) && resetNamespace !== true) {
return `${dsl.parent}.${name}`;
} else {
return name;
}
}

function createRoute(dsl: DSL, name: string, options: RouteOptions = {}, callback?: MatchCallback) {
function createRoute(
dsl: DSLImpl,
name: string,
options: RouteOptions = {},
callback?: MatchCallback
) {
let fullName = getFullName(dsl, name, options.resetNamespace);

if (typeof options.path !== 'string') {
Expand Down
10 changes: 5 additions & 5 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { cancel, once, run, scheduleOnce } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import EmberLocation, { EmberLocation as IEmberLocation } from '../location/api';
import { calculateCacheKey, extractRouteArgs, getActiveTargetName, resemblesURL } from '../utils';
import EmberRouterDSL from './dsl';
import DSL from './dsl';
import Route, {
defaultSerialize,
hasDefaultSerialize,
Expand Down Expand Up @@ -466,7 +466,7 @@ class EmberRouter extends EmberObject {
dsl.route(
'application',
{ path: '/', resetNamespace: true, overrideNameAssertion: true },
function(this: EmberRouterDSL) {
function() {
for (let i = 0; i < dslCallbacks.length; i++) {
dslCallbacks[i].call(this);
}
Expand All @@ -482,7 +482,7 @@ class EmberRouter extends EmberObject {
routerMicrolib.map(dsl.generate());
}

_buildDSL() {
_buildDSL(): DSL {
let enableLoadingSubstates = this._hasModuleBasedResolver();
let router = this;
let owner = getOwner(this);
Expand All @@ -498,7 +498,7 @@ class EmberRouter extends EmberObject {
},
};

return new EmberRouterDSL(null, options);
return new DSL(null, options);
}

init() {
Expand Down Expand Up @@ -1735,7 +1735,7 @@ EmberRouter.reopenClass({
},

_routePath(routeInfos: PrivateRouteInfo[]) {
let path = [];
let path: string[] = [];

// We have to handle coalescing resource names that
// are prefixed with their parent's names, e.g.
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ if (DEBUG) {
*/
setDebugFunction('deprecateFunc', function deprecateFunc(...args: any[]) {
if (args.length === 3) {
let [message, options, func] = args as [string, DeprecationOptions, () => any];
return function(this: any) {
let [message, options, func] = args as [string, DeprecationOptions, (...args: any[]) => any];
return function(this: any, ...args: any[]) {
deprecate(message, false, options);
return func.apply(this, arguments);
return func.apply(this, args);
};
} else {
let [message, func] = args;
Expand Down
Loading

0 comments on commit da2307a

Please sign in to comment.