Skip to content

Commit

Permalink
Update Glimmer-VM
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Mar 2, 2018
1 parent 8ef8dc6 commit 174b27e
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 142 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions broccoli/to-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = function toES5(tree, _options) {
['check-es2015-constants'],
['transform-es2015-classes', { loose: true }],
['transform-proto-to-assign'],
['transform-object-assign'],
injectNodeGlobals,
['transform-es2015-modules-amd', { noInterop: true, strict: true }],
enifed
Expand Down
3 changes: 3 additions & 0 deletions broccoli/transforms/inject-babel-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ function injectBabelHelpers() {
return {
pre(file) {
file.set('helperGenerator', function (name) {
if (name === 'extends') {
return file.addImport('ember-utils', 'assign', name);
}
return file.addImport('ember-babel', name, name);
});
}
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
"resolve": "^1.5.0"
},
"devDependencies": {
"@glimmer/compiler": "^0.32.1",
"@glimmer/interfaces": "^0.32.1",
"@glimmer/node": "^0.32.1",
"@glimmer/opcode-compiler": "^0.32.1",
"@glimmer/program": "^0.32.1",
"@glimmer/reference": "^0.32.1",
"@glimmer/runtime": "^0.32.1",
"@glimmer/compiler": "^0.32.3",
"@glimmer/interfaces": "^0.32.3",
"@glimmer/node": "^0.32.3",
"@glimmer/opcode-compiler": "^0.32.3",
"@glimmer/program": "^0.32.3",
"@glimmer/reference": "^0.32.3",
"@glimmer/runtime": "^0.32.3",
"@types/rsvp": "^4.0.1",
"auto-dist-tag": "^0.1.5",
"aws-sdk": "^2.46.0",
Expand All @@ -83,6 +83,7 @@
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-proto-to-assign": "^6.26.0",
"babel-template": "^6.26.0",
"backburner.js": "2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-application/lib/system/engine-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi
'-view-registry:main',
`renderer:-${env.isInteractive ? 'dom' : 'inert'}`,
'service:-document',
P`template-options:main`,
P`template-compiler:main`,
];

if (env.isInteractive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ moduleFor('Application', class extends ApplicationTestCase {
verifyRegistration(assert, application, P`template:components/-default`);
verifyRegistration(assert, application, 'template:-outlet');
verifyInjection(assert, application, 'view:-outlet', 'template', 'template:-outlet');
verifyInjection(assert, application, 'template', 'options', P`template-options:main`);
verifyInjection(assert, application, 'template', 'compiler', P`template-compiler:main`);

assert.deepEqual(application.registeredOptionsForType('helper'), { instantiate: false }, `optionsForType 'helper'`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-application/tests/system/engine_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ moduleFor('Engine', class extends TestCase {
verifyRegistration(assert, engine, P`template:components/-default`);
verifyRegistration(assert, engine, 'template:-outlet');
verifyInjection(assert, engine, 'view:-outlet', 'template', 'template:-outlet');
verifyInjection(assert, engine, 'template', 'options', P`template-options:main`);
verifyInjection(assert, engine, 'template', 'compiler', P`template-compiler:main`);
assert.deepEqual(engine.registeredOptionsForType('helper'), { instantiate: false }, `optionsForType 'helper'`);
}
});
8 changes: 3 additions & 5 deletions packages/ember-glimmer/lib/compile-time-lookup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { CompilableTemplate, ComponentCapabilities, Option, ProgramSymbolTable } from '@glimmer/interfaces';
import { CompileTimeLookup as ICompileTimeLookup } from '@glimmer/opcode-compiler';
import { CompilableTemplate, CompileTimeLookup as ICompileTimeLookup, ComponentCapabilities, Option, ProgramSymbolTable } from '@glimmer/interfaces';
import { ComponentDefinition, ComponentManager, WithStaticLayout } from '@glimmer/runtime';
import { OwnedTemplateMeta } from 'ember-views';
import RuntimeResolver from './resolver';

interface StaticComponentManager<DefinitionState> extends WithStaticLayout<any, DefinitionState, OwnedTemplateMeta, RuntimeResolver>,
ComponentManager<any, DefinitionState> {
interface StaticComponentManager<DefinitionState> extends WithStaticLayout<any, DefinitionState, OwnedTemplateMeta, RuntimeResolver>, ComponentManager<any, DefinitionState> {
}

export default class CompileTimeLookup implements ICompileTimeLookup<OwnedTemplateMeta> {
Expand Down Expand Up @@ -42,7 +40,7 @@ export default class CompileTimeLookup implements ICompileTimeLookup<OwnedTempla
}

lookupComponentDefinition(name: string, referrer: OwnedTemplateMeta): Option<number> {
return this.resolver.lookupComponentDefinition(name, referrer);
return this.resolver.lookupComponentHandle(name, referrer);
}

lookupPartial(name: string, referrer: OwnedTemplateMeta): Option<number> {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class RootState {
this.render = () => {
let layout = template.asLayout();
let handle = layout.compile();
let iterator = renderMain(layout['options'].program,
let iterator = renderMain(layout['compiler'].program,
env,
self,
dynamicScope,
Expand Down
36 changes: 17 additions & 19 deletions packages/ember-glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
Option,
RuntimeResolver as IRuntimeResolver
} from '@glimmer/interfaces';
import { LazyOpcodeBuilder, Macros, OpcodeBuilderConstructor, PartialDefinition, TemplateOptions } from '@glimmer/opcode-compiler';
import { LazyConstants, Program } from '@glimmer/program';
import { LazyCompiler, Macros, PartialDefinition } from '@glimmer/opcode-compiler';
import {
getDynamicVar,
Helper,
Expand Down Expand Up @@ -84,12 +83,7 @@ const BUILTIN_MODIFIERS = {
};

export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMeta> {
public templateOptions: TemplateOptions<OwnedTemplateMeta> = {
program: new Program<OwnedTemplateMeta>(new LazyConstants(this)),
macros: new Macros(),
resolver: new CompileTimeLookup(this),
Builder: LazyOpcodeBuilder as OpcodeBuilderConstructor,
};
public compiler: LazyCompiler<OwnedTemplateMeta>;

private handles: any[] = [
undefined, // ensure no falsy handle
Expand All @@ -111,23 +105,33 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
public templateCacheMisses = 0;

constructor() {
populateMacros(this.templateOptions.macros);
let macros = new Macros();
populateMacros(macros);
this.compiler = new LazyCompiler<OwnedTemplateMeta>(
new CompileTimeLookup(this),
this,
macros
);
}

/*** IRuntimeResolver ***/

/**
* Called while executing Append Op.PushDynamicComponentManager if string
*/
lookupComponent(name: string, meta: OwnedTemplateMeta): Option<ComponentDefinition> {
let handle = this.lookupComponentDefinition(name, meta);
lookupComponentDefinition(name: string, meta: OwnedTemplateMeta): Option<ComponentDefinition> {
let handle = this.lookupComponentHandle(name, meta);
if (handle === null) {
assert(`Could not find component named "${name}" (no component or template with that name was found)`);
return null;
}
return this.resolve(handle);
}

lookupComponentHandle(name: string, meta: OwnedTemplateMeta) {
return this.handle(this._lookupComponentDefinition(name, meta));
}

/**
* Called by RuntimeConstants to lookup unresolved handles.
*/
Expand All @@ -147,13 +151,6 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
return null;
}

/**
* Called by CompileTimeLookup compiling the Component OpCode
*/
lookupComponentDefinition(name: string, meta: OwnedTemplateMeta): Option<number> {
return this.handle(this._lookupComponentDefinition(name, meta));
}

/**
* Called by CompileTimeLookup compiling the
*/
Expand Down Expand Up @@ -184,7 +181,8 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
}
let template = cache.get(factory);
if (template === undefined) {
const injections: Injections = { options: this.templateOptions };
const { compiler } = this;
const injections: Injections = { compiler };
setOwner(injections, owner);
template = factory.create(injections);
cache.set(factory, template);
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-glimmer/lib/setup-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import Environment from './environment';
import loc from './helpers/loc';
import { InertRenderer, InteractiveRenderer } from './renderer';
import TemplateOptions from './template-options';
import TemplateCompiler from './template-compiler';
import ComponentTemplate from './templates/component';
import OutletTemplate from './templates/outlet';
import RootTemplate from './templates/root';
Expand Down Expand Up @@ -82,9 +82,9 @@ export function setupEngineRegistry(registry: Registry) {

registry.register('service:-glimmer-environment', Environment);

registry.register(P`template-options:main`, TemplateOptions);
registry.register(P`template-compiler:main`, TemplateCompiler);

registry.injection('template', 'options', P`template-options:main`);
registry.injection('template', 'compiler', P`template-compiler:main`);

registry.optionsForType('helper', { instantiate: false });

Expand Down
8 changes: 4 additions & 4 deletions packages/ember-glimmer/lib/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function refineInlineSyntax(name: string, params: Option<Core.Params>, hash: Opt
assert(
`You attempted to overwrite the built-in helper "${name}" which is not allowed. Please rename the helper.`,
!(
(builder.resolver as CompileTimeLookup)['resolver']['builtInHelpers'][name] &&
(builder.compiler['resolver'] as CompileTimeLookup)['resolver']['builtInHelpers'][name] &&
builder.referrer.owner.hasRegistration(`helper:${name}`)
)
);
if (name.indexOf('-') === -1) {
return false;
}

let handle = builder.resolver.lookupComponentDefinition(name, builder.referrer);
let handle = builder.compiler['resolver'].lookupComponentDefinition(name, builder.referrer);

if (handle !== null) {
builder.component.static(handle, [params === null ? [] : params, hashToArgs(hash), null, null]);
Expand All @@ -42,7 +42,7 @@ function refineBlockSyntax(name: string, params: Core.Params, hash: Core.Hash, t
return false;
}

let handle = builder.resolver.lookupComponentDefinition(name, builder.referrer);
let handle = builder.compiler['resolver'].lookupComponentDefinition(name, builder.referrer);

if (handle !== null) {
wrapComponentClassAttribute(hash);
Expand All @@ -55,7 +55,7 @@ function refineBlockSyntax(name: string, params: Core.Params, hash: Core.Hash, t
assert(
`Helpers may not be used in the block form, for example {{#${name}}}{{/${name}}}. Please use a component, or alternatively use the helper in combination with a built-in Ember helper, for example {{#if (${name})}}{{/if}}.`,
!(() => {
const resolver = (builder.resolver as CompileTimeLookup)['resolver'];
const resolver = (builder.compiler['resolver'] as CompileTimeLookup)['resolver'];
const { owner, moduleName } = builder.referrer;
if (name === 'component' || resolver['builtInHelpers'][name]) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/syntax/-text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { wrapComponentClassAttribute } from '../utils/bindings';
import { hashToArgs } from './utils';

export function textAreaMacro(_name: string, params: Option<WireFormat.Core.Params>, hash: Option<WireFormat.Core.Hash>, builder: OpcodeBuilder<OwnedTemplateMeta>) {
let definition = builder.resolver.lookupComponentDefinition('-text-area', builder.referrer);
let definition = builder.compiler['resolver'].lookupComponentDefinition('-text-area', builder.referrer);
wrapComponentClassAttribute(hash);
builder.component.static(definition!, [params || [], hashToArgs(hash), null, null]);
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/syntax/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { wrapComponentClassAttribute } from '../utils/bindings';
import { hashToArgs } from './utils';

function buildSyntax(type: string, params: any[], hash: any, builder: OpcodeBuilder<OwnedTemplateMeta>) {
let definition = builder.resolver.lookupComponentDefinition(type, builder.referrer);
let definition = builder.compiler['resolver'].lookupComponentDefinition(type, builder.referrer);
builder.component.static(definition!, [params, hashToArgs(hash), null, null]);
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/ember-glimmer/lib/template-compiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Compiler } from '@glimmer/interfaces';
import RuntimeResolver from './resolver';

// factory for DI
export default {
create(): Compiler {
return new RuntimeResolver().compiler;
}
};
10 changes: 0 additions & 10 deletions packages/ember-glimmer/lib/template-options.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/ember-glimmer/lib/template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Template } from '@glimmer/interfaces';
import { templateFactory, TemplateFactory, TemplateOptions } from '@glimmer/opcode-compiler';
import { LazyCompiler, templateFactory, TemplateFactory } from '@glimmer/opcode-compiler';
import { SerializedTemplateWithLazyBlock } from '@glimmer/wire-format';
import { getOwner } from 'ember-utils';
import { OwnedTemplateMeta, StaticTemplateMeta } from 'ember-views';
Expand All @@ -12,7 +12,7 @@ export default function template(json: StaticTemplate): Factory {
}

export interface Injections {
options: TemplateOptions<OwnedTemplateMeta>;
compiler: LazyCompiler<StaticTemplateMeta>;
[key: string]: any;
}

Expand All @@ -33,6 +33,6 @@ class FactoryWrapper implements Factory {

create(injections: Injections): OwnedTemplate {
const owner = getOwner(injections);
return this.factory.create(injections.options, { owner });
return this.factory.create(injections.compiler, { owner });
}
}
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/utils/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class CachedReference extends EmberPathReference {
value() {
let { tag, _lastRevision, _lastValue } = this;

if (!_lastRevision || !tag.validate(_lastRevision)) {
if (_lastRevision === null || !tag.validate(_lastRevision)) {
_lastValue = this._lastValue = this.compute();
this._lastRevision = tag.value();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ class ContentTestGenerator {
this.assertStableRerender();

this.runTask(() => set(this.context, 'value', 'hello'));

this.assertContent('hello');
this.assertInvariants();

Expand Down Expand Up @@ -612,6 +611,7 @@ moduleFor('Dynamic content tests (content position)', class extends DynamicConte
assertContent(content) {
this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one text node');
this.assertTextNode(this.firstChild, content);
// this.takeSnapshot();
}

});
Expand Down
6 changes: 5 additions & 1 deletion packages/ember-utils/lib/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export function assign(original) {
return original;
}

export default Object.assign || assign;
// Note: We use the bracket notation so
// that the babel plugin does not
// transform it.
// https://www.npmjs.com/package/babel-plugin-transform-object-assign
export default Object['assign'] || assign;
2 changes: 1 addition & 1 deletion packages/internal-test-helpers/lib/test-cases/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class RenderingTestCase extends AbstractRenderingTestCase {
let { owner } = this;

this.env = owner.lookup('service:-glimmer-environment');
this.templateOptions = owner.lookup(P`template-options:main`);
this.templateOptions = owner.lookup(P`template-compiler:main`);
this.compileTimeLookup = this.templateOptions.resolver;
this.runtimeResolver = this.compileTimeLookup.resolver;
}
Expand Down
Loading

0 comments on commit 174b27e

Please sign in to comment.