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

Revert "Merge pull request #444 from tildeio/artisinal-code-stripping" #456

Merged
merged 2 commits into from
Apr 18, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"glob": "^7.0.5",
"loader.js": "^4.0.10",
"qunit-tap": "^1.5.1",
"qunitjs": "^2.1.1",
"qunitjs": "2.2.0",
"semver": "^5.3.0",
"testem": "github:rwjblue/testem#todo-support",
"tslint": "^4.0.2",
Expand Down
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: 4 additions & 0 deletions packages/@glimmer/env-flags/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This will be used during tests
// But will be replaced with an inlined
// flag in production that will allow for DCE
export const DEBUG = true;
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
22 changes: 12 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, } from '@glimmer/util';
import { Option, Destroyable, Stack, LinkedList, LinkedListNode, assert, expect } from '@glimmer/util';

import { Environment } from './environment';

Expand Down Expand Up @@ -114,16 +114,16 @@ export class ElementStack implements Cursor {
this.nextSiblingStack.push(this.nextSibling);
}

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

expectOperations(_: string): ElementOperations {
return this.operations!;
expectOperations(method: string): ElementOperations {
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
Loading