Skip to content

Commit

Permalink
Revert "Merge pull request #444 from tildeio/artisinal-code-stripping"
Browse files Browse the repository at this point in the history
This reverts commit 82a2ab8, reversing
changes made to c56ef68.
  • Loading branch information
chadhietala committed Apr 6, 2017
1 parent d58ffb6 commit 65e91d5
Show file tree
Hide file tree
Showing 26 changed files with 573 additions and 46 deletions.
9 changes: 7 additions & 2 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 } from "@glimmer/util";
import { Stack, DictSet, Option, expect } 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 this.blocks.current;
return expect(this.blocks.current, 'Expected a block on the stack');
}

process(): Template<T> {
Expand Down Expand Up @@ -228,6 +228,8 @@ 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 @@ -350,6 +352,7 @@ 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 @@ -364,6 +367,7 @@ 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 @@ -391,6 +395,7 @@ 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: 4 additions & 1 deletion packages/@glimmer/compiler/lib/template-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -34,7 +35,7 @@ export default class TemplateCompiler<T extends TemplateMeta> {
}

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

process(actions: Action[]): Action[] {
Expand Down Expand Up @@ -306,6 +307,7 @@ 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 @@ -323,6 +325,7 @@ 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: 3 additions & 2 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 } from '@glimmer/util';
import { Dict, Option, dict, unreachable, expect } from '@glimmer/util';

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

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

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

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

private getCurrentFrame(): Option<Frame> {
Expand Down
4 changes: 3 additions & 1 deletion 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 } from '@glimmer/util';
import { LinkedList, ListNode, Opaque, Option, dict, expect } from '@glimmer/util';
import { VersionedPathReference as PathReference, Tag } from './validators';

export interface IterationItem<T, U> {
Expand Down Expand Up @@ -247,6 +247,8 @@ 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: 1 addition & 0 deletions packages/@glimmer/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {

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

export {
Expand Down
18 changes: 10 additions & 8 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, } from '@glimmer/util';
import { Option, Destroyable, Stack, LinkedList, LinkedListNode, assert, expect } from '@glimmer/util';

import { Environment } from './environment';

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

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

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

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

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 = elementStack.current!;
this.element = expect(elementStack.current, "can't pop past the last element");
this.nextSibling = nextSiblingStack.current;

return topElement;
Expand Down Expand Up @@ -181,8 +181,7 @@ export class ElementStack implements Cursor {

popBlock(): Tracker {
this.block().finalize(this);

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

openElement(tag: string, _operations?: ElementOperations): Simple.Element {
Expand All @@ -198,7 +197,7 @@ export class ElementStack implements Cursor {

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

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

Expand Down Expand Up @@ -414,12 +413,15 @@ 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 } from '@glimmer/util';
import { Option, unwrap } 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 && svg.firstChild.namespaceURI === SVG_NAMESPACE) {
if (svg.childNodes.length === 1 && unwrap(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, fillNulls, EMPTY_ARRAY } from '@glimmer/util';
import { Option, Stack, Opaque, dict, expect, 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 this.labelsStack.current;
return expect(this.labelsStack.current, 'bug: not in a label stack');
}

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

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

Expand Down
8 changes: 8 additions & 0 deletions packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ 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: 25 additions & 0 deletions packages/@glimmer/runtime/lib/compiled/opcodes/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ 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 @@ -275,6 +285,21 @@ 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: 46 additions & 4 deletions packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { UpdatingOpcode } from '../../opcodes';
import { OpcodeJSON, 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 } from '@glimmer/util';
import { FIXME, Option, Opaque, Dict, unwrap, expect } from '@glimmer/util';
import {
CachedReference,
Reference,
Expand Down Expand Up @@ -299,7 +299,7 @@ export class ComponentElementOperations implements ElementOperations {
}

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

Expand Down Expand Up @@ -371,6 +371,13 @@ 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 @@ -410,7 +417,7 @@ export class DynamicAttribute implements Attribute {
patch(env: Environment) {
let { element, cache } = this;

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

if (isModified(value)) {
this.attributeManager.updateAttribute(env, element as FIXME<Element, 'needs to be reified properly'>, value, this.namespace);
Expand All @@ -431,6 +438,31 @@ 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 @@ -464,4 +496,14 @@ 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

0 comments on commit 65e91d5

Please sign in to comment.