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

Artisanal Production Builds By Chad #444

Merged
merged 1 commit into from
Mar 26, 2017
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
9 changes: 2 additions & 7 deletions packages/@glimmer/compiler/lib/javascript-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as WireFormat from '@glimmer/wire-format';
import { assert } from "@glimmer/util";
import { Stack, DictSet, Option, expect } from "@glimmer/util";
import { Stack, DictSet, Option } from "@glimmer/util";
import { AST } from '@glimmer/syntax';
import { BlockSymbolTable, ProgramSymbolTable } from './template-visitor';

Expand Down Expand Up @@ -169,7 +169,7 @@ export default class JavaScriptCompiler<T extends TemplateMeta> {
}

get currentBlock(): Block {
return expect(this.blocks.current, 'Expected a block on the stack');
return this.blocks.current;
}

process(): Template<T> {
Expand Down Expand Up @@ -228,8 +228,6 @@ export default class JavaScriptCompiler<T extends TemplateMeta> {
let hash = this.popValue<Hash>();

let blocks = this.template.block.blocks;
assert(typeof template !== 'number' || blocks[template] !== null, 'missing block in the compiler');
assert(typeof inverse !== 'number' || blocks[inverse] !== null, 'missing block in the compiler');

this.push([Ops.Block, name, params, hash, blocks[template], blocks[inverse]]);
}
Expand Down Expand Up @@ -352,7 +350,6 @@ export default class JavaScriptCompiler<T extends TemplateMeta> {

endComponent(): [WireFormat.Statements.Attribute[], WireFormat.Core.Hash, Option<WireFormat.SerializedInlineBlock>] {
let component = this.blocks.pop();
assert(component instanceof ComponentBlock, "Compiler bug: endComponent() should end a component");
return (component as ComponentBlock).toJSON();
}

Expand All @@ -367,7 +364,6 @@ export default class JavaScriptCompiler<T extends TemplateMeta> {
}

prepareObject(size: number) {
assert(this.values.length >= size, `Expected ${size} values on the stack, found ${this.values.length}`);

let keys: string[] = new Array(size);
let values: Expression[] = new Array(size);
Expand Down Expand Up @@ -395,7 +391,6 @@ export default class JavaScriptCompiler<T extends TemplateMeta> {
}

popValue<T extends StackValue>(): T {
assert(this.values.length, "No expression found on stack");
return this.values.pop() as T;
}
}
5 changes: 1 addition & 4 deletions packages/@glimmer/compiler/lib/template-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import TemplateVisitor, { SymbolTable, Action } from "./template-visitor";
import JavaScriptCompiler, { Template } from "./javascript-compiler";
import { Stack, getAttrNamespace } from "@glimmer/util";
import { assert, expect } from "@glimmer/util";
import { TemplateMeta } from "@glimmer/wire-format";
import { AST, isLiteral } from '@glimmer/syntax';

Expand Down Expand Up @@ -35,7 +34,7 @@ export default class TemplateCompiler<T extends TemplateMeta> {
}

get symbols(): SymbolTable {
return expect(this.symbolStack.current, 'Expected a symbol table on the stack');
return this.symbolStack.current;
}

process(actions: Action[]): Action[] {
Expand Down Expand Up @@ -307,7 +306,6 @@ export default class TemplateCompiler<T extends TemplateMeta> {
for (let i = params.length - 1; i >= 0; i--) {
let param = params[i];

assert(this[param.type], `Unimplemented ${param.type} on TemplateCompiler`);
(this[param.type] as any)(param);
}

Expand All @@ -325,7 +323,6 @@ export default class TemplateCompiler<T extends TemplateMeta> {
for (let i = pairs.length - 1; i >= 0; i--) {
let { key, value } = pairs[i];

assert(this[value.type], `Unimplemented ${value.type} on TemplateCompiler`);
(this[value.type] as any)(value);
this.opcode('literal', null, key);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/@glimmer/compiler/lib/template-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AST } from '@glimmer/syntax';
import { Core } from '@glimmer/wire-format';
import { Dict, Option, dict, unreachable, expect } from '@glimmer/util';
import { Dict, Option, dict } from '@glimmer/util';

export abstract class SymbolTable {
static top(): ProgramSymbolTable {
Expand Down Expand Up @@ -35,7 +35,6 @@ export class ProgramSymbolTable extends SymbolTable {
}

get(_name: string): never {
throw unreachable();
}

getLocalsMap(): Dict<number> {
Expand Down Expand Up @@ -345,7 +344,7 @@ export default class TemplateVisitor {
// Frame helpers

private get currentFrame(): Frame {
return expect(this.getCurrentFrame(), "Expected a current frame");
return this.getCurrentFrame();
}

private getCurrentFrame(): Option<Frame> {
Expand Down
4 changes: 1 addition & 3 deletions packages/@glimmer/reference/lib/iterable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LinkedList, ListNode, Opaque, Option, dict, expect } from '@glimmer/util';
import { LinkedList, ListNode, Opaque, Option, dict } from '@glimmer/util';
import { VersionedPathReference as PathReference, Tag } from './validators';

export interface IterationItem<T, U> {
Expand Down Expand Up @@ -247,8 +247,6 @@ export class IteratorSynchronizer {
private nextRetain(item: OpaqueIterationItem) {
let { artifacts, current } = this;

current = expect(current, 'BUG: current is empty');

current.update(item);
this.current = artifacts.nextNode(current);
this.target.retain(item.key, current.value, current.memo);
Expand Down
1 change: 0 additions & 1 deletion packages/@glimmer/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export {

export {
Register,
debugSlice
} from './lib/opcodes';

export {
Expand Down
17 changes: 7 additions & 10 deletions packages/@glimmer/runtime/lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Bounds, { Cursor, DestroyableBounds, clear } from './bounds';

import { DOMChanges, DOMTreeConstruction } from './dom/helper';

import { Option, Destroyable, Stack, LinkedList, LinkedListNode, assert, expect } from '@glimmer/util';
import { Option, Destroyable, Stack, LinkedList, LinkedListNode, } from '@glimmer/util';

import { Environment } from './environment';

Expand Down Expand Up @@ -115,15 +115,15 @@ export class ElementStack implements Cursor {
}

expectConstructing(method: string): Simple.Element {
return expect(this.constructing, `${method} should only be called while constructing an element`);
return this.constructing;
}

expectOperations(method: string): ElementOperations {
return expect(this.operations, `${method} should only be called while constructing an element`);
return this.operations;
}

block(): Tracker {
return expect(this.blockStack.current, "Expected a current block tracker");
return this.blockStack.current;
}

popElement() {
Expand All @@ -133,7 +133,7 @@ export class ElementStack implements Cursor {
nextSiblingStack.pop();
// LOGGER.debug(`-> element stack ${this.elementStack.toArray().map(e => e.tagName).join(', ')}`);

this.element = expect(elementStack.current, "can't pop past the last element");
this.element = elementStack.current;
this.nextSibling = nextSiblingStack.current;

return topElement;
Expand Down Expand Up @@ -182,7 +182,7 @@ export class ElementStack implements Cursor {
popBlock(): Tracker {
this.block().finalize(this);

return expect(this.blockStack.pop(), "Expected popBlock to return a block");
return this.blockStack.pop();
}

openElement(tag: string, operations = this.defaultOperations): Simple.Element {
Expand All @@ -196,7 +196,7 @@ export class ElementStack implements Cursor {

flushElement() {
let parent = this.element;
let element = expect(this.constructing, `flushElement should only be called when constructing an element`);
let element = this.constructing;

this.dom.insertBefore(parent, element, this.nextSibling);

Expand Down Expand Up @@ -412,15 +412,12 @@ class BlockListTracker implements Tracker {
}

openElement(_element: Element) {
assert(false, 'Cannot openElement directly inside a block list');
}

closeElement() {
assert(false, 'Cannot closeElement directly inside a block list');
}

newNode(_node: Node) {
assert(false, 'Cannot create a new node directly inside a block list');
}

newBounds(_bounds: Bounds) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@glimmer/runtime/lib/compat/svg-inner-html-fix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bounds, ConcreteBounds } from '../bounds';
import { moveNodesBefore, DOMChanges, DOMTreeConstruction } from '../dom/helper';
import { Option, unwrap } from '@glimmer/util';
import { Option } from '@glimmer/util';

export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
export type SVG_NAMESPACE = typeof SVG_NAMESPACE;
Expand Down Expand Up @@ -85,7 +85,7 @@ function shouldApplyFix(document: Document, svgNamespace: SVG_NAMESPACE) {
// Safari: Will throw, insertAdjacentHTML is not present on SVG
} finally {
// FF: Old versions will create a node in the wrong namespace
if (svg.childNodes.length === 1 && unwrap(svg.firstChild).namespaceURI === SVG_NAMESPACE) {
if (svg.childNodes.length === 1 && svg.firstChild.namespaceURI === SVG_NAMESPACE) {
// The test worked as expected, no fix required
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/runtime/lib/compiled/opcodes/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vm from './vm';
import { Insertion } from '../../upsert';
import { Register } from '../../opcodes';
import * as WireFormat from '@glimmer/wire-format';
import { Option, Stack, Opaque, dict, expect, fillNulls, EMPTY_ARRAY } from '@glimmer/util';
import { Option, Stack, Opaque, dict, fillNulls, EMPTY_ARRAY } from '@glimmer/util';
import {
Constants,
ConstantString,
Expand Down Expand Up @@ -98,15 +98,15 @@ export abstract class BasicOpcodeBuilder {
// helpers

private get labels(): Labels {
return expect(this.labelsStack.current, 'bug: not in a label stack');
return this.labelsStack.current;
}

startLabels() {
this.labelsStack.push(new Labels());
}

stopLabels() {
let label = expect(this.labelsStack.pop(), 'unbalanced push and pop labels');
let label = this.labelsStack.pop();
label.patch(this.program);
}

Expand Down
8 changes: 0 additions & 8 deletions packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ export class UpdateComponentOpcode extends UpdatingOpcode {

manager.update(component, dynamicScope);
}

toJSON(): OpcodeJSON {
return {
guid: this._guid,
type: this.type,
args: [JSON.stringify(this.name)]
};
}
}

export class DidUpdateLayoutOpcode extends UpdatingOpcode {
Expand Down
25 changes: 0 additions & 25 deletions packages/@glimmer/runtime/lib/compiled/opcodes/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,6 @@ abstract class UpdateOpcode<T extends Insertion> extends UpdatingOpcode {
bounds.update(upsert.bounds);
}
}

toJSON(): OpcodeJSON {
let { _guid: guid, type, cache } = this;

return {
guid,
type,
details: { lastValue: JSON.stringify(cache.peek()) }
};
}
}

abstract class GuardedUpdateOpcode<T extends Insertion> extends UpdateOpcode<T> {
Expand Down Expand Up @@ -285,21 +275,6 @@ abstract class GuardedUpdateOpcode<T extends Insertion> extends UpdateOpcode<T>

return null as any;
}

toJSON(): OpcodeJSON {
let { _guid: guid, type, deopted } = this;

if (deopted) {
return {
guid,
type,
deopted: true,
children: [deopted.toJSON()]
};
} else {
return super.toJSON();
}
}
}

export class OptimizedCautiousAppendOpcode extends AppendDynamicOpcode<CautiousInsertion> {
Expand Down
50 changes: 4 additions & 46 deletions packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OpcodeJSON, UpdatingOpcode } from '../../opcodes';
import { UpdatingOpcode } from '../../opcodes';
import { VM, UpdatingVM } from '../../vm';
import { Arguments } from '../../vm/arguments';
import * as Simple from '../../dom/interfaces';
import { FIX_REIFICATION } from '../../dom/interfaces';
import { Environment } from '../../environment';
import { FIXME, Option, Opaque, Dict, unwrap, expect } from '@glimmer/util';
import { FIXME, Option, Opaque } from '@glimmer/util';
import {
CachedReference,
Reference,
Expand Down Expand Up @@ -299,7 +299,7 @@ export class ComponentElementOperations implements ElementOperations {
}

attributeNames.push(name);
unwrap(attributes).push(attribute);
attributes.push(attribute);
}
}

Expand Down Expand Up @@ -371,13 +371,6 @@ export class UpdateModifierOpcode extends UpdatingOpcode {
this.lastUpdated = tag.value();
}
}

toJSON(): OpcodeJSON {
return {
guid: this._guid,
type: this.type
};
}
}

export interface Attribute {
Expand Down Expand Up @@ -417,7 +410,7 @@ export class DynamicAttribute implements Attribute {
patch(env: Environment) {
let { element, cache } = this;

let value = expect(cache, 'must patch after flush').revalidate();
let value = cache.revalidate();

if (isModified(value)) {
this.attributeManager.updateAttribute(env, element as FIXME<Element, 'needs to be reified properly'>, value, this.namespace);
Expand All @@ -438,31 +431,6 @@ export class DynamicAttribute implements Attribute {
return new PatchElementOpcode(this);
}
}

toJSON(): Dict<Option<string>> {
let { element, namespace, name, cache } = this;

let formattedElement = formatElement(element);
let lastValue = expect(cache, 'must serialize after flush').peek() as string;

if (namespace) {
return {
element: formattedElement,
type: 'attribute',
namespace,
name,
lastValue
};
}

return {
element: formattedElement,
type: 'attribute',
namespace: namespace === undefined ? null : namespace,
name,
lastValue
};
}
}

function formatElement(element: Simple.Element): string {
Expand Down Expand Up @@ -496,14 +464,4 @@ export class PatchElementOpcode extends UpdatingOpcode {
evaluate(vm: UpdatingVM) {
this.operation.patch(vm.env);
}

toJSON(): OpcodeJSON {
let { _guid, type, operation } = this;

return {
guid: _guid,
type,
details: operation.toJSON()
};
}
}
Loading