ember-material-icons
Version:
Google Material icons for your ember-cli app
1,428 lines (1,215 loc) • 796 kB
JavaScript
;(function() {
/*!
* @overview Ember - JavaScript Application Framework
* @copyright Copyright 2011-2017 Tilde Inc. and contributors
* Portions Copyright 2006-2011 Strobe Inc.
* Portions Copyright 2008-2011 Apple Inc. All rights reserved.
* @license Licensed under MIT license
* See https://raw.github.com/emberjs/ember.js/master/LICENSE
* @version 2.13.2
*/
var enifed, requireModule, Ember;
var mainContext = this; // Used in ember-environment/lib/global.js
(function() {
var isNode = typeof window === 'undefined' &&
typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
if (!isNode) {
Ember = this.Ember = this.Ember || {};
}
if (typeof Ember === 'undefined') { Ember = {}; }
if (typeof Ember.__loader === 'undefined') {
var registry = {};
var seen = {};
enifed = function(name, deps, callback) {
var value = { };
if (!callback) {
value.deps = [];
value.callback = deps;
} else {
value.deps = deps;
value.callback = callback;
}
registry[name] = value;
};
requireModule = function(name) {
return internalRequire(name, null);
};
// setup `require` module
requireModule['default'] = requireModule;
requireModule.has = function registryHas(moduleName) {
return !!registry[moduleName] || !!registry[moduleName + '/index'];
};
function missingModule(name, referrerName) {
if (referrerName) {
throw new Error('Could not find module ' + name + ' required by: ' + referrerName);
} else {
throw new Error('Could not find module ' + name);
}
}
function internalRequire(_name, referrerName) {
var name = _name;
var mod = registry[name];
if (!mod) {
name = name + '/index';
mod = registry[name];
}
var exports = seen[name];
if (exports !== undefined) {
return exports;
}
exports = seen[name] = {};
if (!mod) {
missingModule(_name, referrerName);
}
var deps = mod.deps;
var callback = mod.callback;
var reified = new Array(deps.length);
for (var i = 0; i < deps.length; i++) {
if (deps[i] === 'exports') {
reified[i] = exports;
} else if (deps[i] === 'require') {
reified[i] = requireModule;
} else {
reified[i] = internalRequire(deps[i], name);
}
}
callback.apply(this, reified);
return exports;
}
requireModule._eak_seen = registry;
Ember.__loader = {
define: enifed,
require: requireModule,
registry: registry
};
} else {
enifed = Ember.__loader.define;
requireModule = Ember.__loader.require;
}
})();
function classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function');
}
}
function inherits(subClass, superClass) {
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : defaults(subClass, superClass);
}
function taggedTemplateLiteralLoose(strings, raw) {
strings.raw = raw;
return strings;
}
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ('value' in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function createClass(Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
}
function interopExportWildcard(obj, defaults) {
var newObj = defaults({}, obj);
delete newObj['default'];
return newObj;
}
function defaults(obj, defaults) {
var keys = Object.getOwnPropertyNames(defaults);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = Object.getOwnPropertyDescriptor(defaults, key);
if (value && value.configurable && obj[key] === undefined) {
Object.defineProperty(obj, key, value);
}
}
return obj;
}
var babelHelpers = {
classCallCheck: classCallCheck,
inherits: inherits,
taggedTemplateLiteralLoose: taggedTemplateLiteralLoose,
slice: Array.prototype.slice,
createClass: createClass,
interopExportWildcard: interopExportWildcard,
defaults: defaults
};
enifed('@glimmer/compiler', ['exports', '@glimmer/syntax', '@glimmer/util', '@glimmer/wire-format'], function (exports, _glimmerSyntax, _glimmerUtil, _glimmerWireFormat) {
'use strict';
var push = Array.prototype.push;
var Frame = function Frame() {
this.parentNode = null;
this.children = null;
this.childIndex = null;
this.childCount = null;
this.childTemplateCount = 0;
this.mustacheCount = 0;
this.actions = [];
this.blankChildTextNodes = null;
this.symbols = null;
};
var SymbolTable = (function () {
function SymbolTable(symbols) {
var parent = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
this.symbols = symbols;
this.parent = parent;
}
/**
* Takes in an AST and outputs a list of actions to be consumed
* by a compiler. For example, the template
*
* foo{{bar}}<div>baz</div>
*
* produces the actions
*
* [['startProgram', [programNode, 0]],
* ['text', [textNode, 0, 3]],
* ['mustache', [mustacheNode, 1, 3]],
* ['openElement', [elementNode, 2, 3, 0]],
* ['text', [textNode, 0, 1]],
* ['closeElement', [elementNode, 2, 3],
* ['endProgram', [programNode]]]
*
* This visitor walks the AST depth first and backwards. As
* a result the bottom-most child template will appear at the
* top of the actions list whereas the root template will appear
* at the bottom of the list. For example,
*
* <div>{{#if}}foo{{else}}bar<b></b>{{/if}}</div>
*
* produces the actions
*
* [['startProgram', [programNode, 0]],
* ['text', [textNode, 0, 2, 0]],
* ['openElement', [elementNode, 1, 2, 0]],
* ['closeElement', [elementNode, 1, 2]],
* ['endProgram', [programNode]],
* ['startProgram', [programNode, 0]],
* ['text', [textNode, 0, 1]],
* ['endProgram', [programNode]],
* ['startProgram', [programNode, 2]],
* ['openElement', [elementNode, 0, 1, 1]],
* ['block', [blockNode, 0, 1]],
* ['closeElement', [elementNode, 0, 1]],
* ['endProgram', [programNode]]]
*
* The state of the traversal is maintained by a stack of frames.
* Whenever a node with children is entered (either a ProgramNode
* or an ElementNode) a frame is pushed onto the stack. The frame
* contains information about the state of the traversal of that
* node. For example,
*
* - index of the current child node being visited
* - the number of mustaches contained within its child nodes
* - the list of actions generated by its child nodes
*/
SymbolTable.prototype.hasLocalVariable = function hasLocalVariable(name) {
var symbols = this.symbols;
var parent = this.parent;
return symbols.indexOf(name) >= 0 || parent && parent.hasLocalVariable(name);
};
return SymbolTable;
})();
function TemplateVisitor() {
this.frameStack = [];
this.actions = [];
this.programDepth = -1;
}
// Traversal methods
TemplateVisitor.prototype.visit = function (node) {
this[node.type](node);
};
TemplateVisitor.prototype.Program = function (program) {
this.programDepth++;
var parentFrame = this.getCurrentFrame();
var programFrame = this.pushFrame();
if (parentFrame) {
program.symbols = new SymbolTable(program.blockParams, parentFrame.symbols);
} else {
program.symbols = new SymbolTable(program.blockParams);
}
var startType = undefined,
endType = undefined;
if (this.programDepth === 0) {
startType = 'startProgram';
endType = 'endProgram';
} else {
startType = 'startBlock';
endType = 'endBlock';
}
programFrame.parentNode = program;
programFrame.children = program.body;
programFrame.childCount = program.body.length;
programFrame.blankChildTextNodes = [];
programFrame.actions.push([endType, [program, this.programDepth]]);
programFrame.symbols = program.symbols;
for (var i = program.body.length - 1; i >= 0; i--) {
programFrame.childIndex = i;
this.visit(program.body[i]);
}
programFrame.actions.push([startType, [program, programFrame.childTemplateCount, programFrame.blankChildTextNodes.reverse()]]);
this.popFrame();
this.programDepth--;
// Push the completed template into the global actions list
if (parentFrame) {
parentFrame.childTemplateCount++;
}
push.apply(this.actions, programFrame.actions.reverse());
};
TemplateVisitor.prototype.ElementNode = function (element) {
var parentFrame = this.getCurrentFrame();
var elementFrame = this.pushFrame();
elementFrame.parentNode = element;
elementFrame.children = element.children;
elementFrame.childCount = element.children.length;
elementFrame.mustacheCount += element.modifiers.length;
elementFrame.blankChildTextNodes = [];
elementFrame.symbols = parentFrame.symbols;
var actionArgs = [element, parentFrame.childIndex, parentFrame.childCount];
elementFrame.actions.push(['closeElement', actionArgs]);
for (var i = element.attributes.length - 1; i >= 0; i--) {
this.visit(element.attributes[i]);
}
for (var i = element.children.length - 1; i >= 0; i--) {
elementFrame.childIndex = i;
this.visit(element.children[i]);
}
elementFrame.actions.push(['openElement', actionArgs.concat([elementFrame.mustacheCount, elementFrame.blankChildTextNodes.reverse()])]);
this.popFrame();
// Propagate the element's frame state to the parent frame
if (elementFrame.mustacheCount > 0) {
parentFrame.mustacheCount++;
}
parentFrame.childTemplateCount += elementFrame.childTemplateCount;
push.apply(parentFrame.actions, elementFrame.actions);
};
TemplateVisitor.prototype.AttrNode = function (attr) {
if (attr.value.type !== 'TextNode') {
this.getCurrentFrame().mustacheCount++;
}
};
TemplateVisitor.prototype.TextNode = function (text) {
var frame = this.getCurrentFrame();
if (text.chars === '') {
frame.blankChildTextNodes.push(domIndexOf(frame.children, text));
}
frame.actions.push(['text', [text, frame.childIndex, frame.childCount]]);
};
TemplateVisitor.prototype.BlockStatement = function (node) {
var frame = this.getCurrentFrame();
frame.mustacheCount++;
frame.actions.push(['block', [node, frame.childIndex, frame.childCount]]);
if (node.inverse) {
this.visit(node.inverse);
}
if (node.program) {
this.visit(node.program);
}
};
TemplateVisitor.prototype.PartialStatement = function (node) {
var frame = this.getCurrentFrame();
frame.mustacheCount++;
frame.actions.push(['mustache', [node, frame.childIndex, frame.childCount]]);
};
TemplateVisitor.prototype.CommentStatement = function (text) {
var frame = this.getCurrentFrame();
frame.actions.push(['comment', [text, frame.childIndex, frame.childCount]]);
};
TemplateVisitor.prototype.MustacheCommentStatement = function () {
// Intentional empty: Handlebars comments should not affect output.
};
TemplateVisitor.prototype.MustacheStatement = function (mustache) {
var frame = this.getCurrentFrame();
frame.mustacheCount++;
frame.actions.push(['mustache', [mustache, frame.childIndex, frame.childCount]]);
};
// Frame helpers
TemplateVisitor.prototype.getCurrentFrame = function () {
return this.frameStack[this.frameStack.length - 1];
};
TemplateVisitor.prototype.pushFrame = function () {
var frame = new Frame();
this.frameStack.push(frame);
return frame;
};
TemplateVisitor.prototype.popFrame = function () {
return this.frameStack.pop();
};
// Returns the index of `domNode` in the `nodes` array, skipping
// over any nodes which do not represent DOM nodes.
function domIndexOf(nodes, domNode) {
var index = -1;
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.type !== 'TextNode' && node.type !== 'ElementNode') {
continue;
} else {
index++;
}
if (node === domNode) {
return index;
}
}
return -1;
}
var Block = (function () {
function Block() {
this.type = "block";
this.statements = [];
this.positionals = [];
}
Block.prototype.toJSON = function toJSON() {
return {
statements: this.statements,
locals: this.positionals
};
};
Block.prototype.push = function push(statement) {
this.statements.push(statement);
};
return Block;
})();
var TemplateBlock = (function (_Block) {
babelHelpers.inherits(TemplateBlock, _Block);
function TemplateBlock() {
_Block.apply(this, arguments);
this.type = "template";
this.yields = new _glimmerUtil.DictSet();
this.named = new _glimmerUtil.DictSet();
this.blocks = [];
this.hasPartials = false;
}
TemplateBlock.prototype.toJSON = function toJSON() {
return {
statements: this.statements,
locals: this.positionals,
named: this.named.toArray(),
yields: this.yields.toArray(),
hasPartials: this.hasPartials
};
};
return TemplateBlock;
})(Block);
var ComponentBlock = (function (_Block2) {
babelHelpers.inherits(ComponentBlock, _Block2);
function ComponentBlock() {
_Block2.apply(this, arguments);
this.type = "component";
this.attributes = [];
this.arguments = [];
this.inParams = true;
}
ComponentBlock.prototype.push = function push(statement) {
if (this.inParams) {
if (_glimmerWireFormat.Statements.isFlushElement(statement)) {
this.inParams = false;
} else if (_glimmerWireFormat.Statements.isArgument(statement)) {
this.arguments.push(statement);
} else if (_glimmerWireFormat.Statements.isAttribute(statement)) {
this.attributes.push(statement);
} else if (_glimmerWireFormat.Statements.isModifier(statement)) {
throw new Error('Compile Error: Element modifiers are not allowed in components');
} else {
throw new Error('Compile Error: only parameters allowed before flush-element');
}
} else {
this.statements.push(statement);
}
};
ComponentBlock.prototype.toJSON = function toJSON() {
var args = this.arguments;
var keys = args.map(function (arg) {
return arg[1];
});
var values = args.map(function (arg) {
return arg[2];
});
return {
attrs: this.attributes,
args: [keys, values],
locals: this.positionals,
statements: this.statements
};
};
return ComponentBlock;
})(Block);
var Template = (function () {
function Template(meta) {
this.meta = meta;
this.block = new TemplateBlock();
}
Template.prototype.toJSON = function toJSON() {
return {
block: this.block.toJSON(),
meta: this.meta
};
};
return Template;
})();
var JavaScriptCompiler = (function () {
function JavaScriptCompiler(opcodes, meta) {
this.blocks = new _glimmerUtil.Stack();
this.values = [];
this.opcodes = opcodes;
this.template = new Template(meta);
}
JavaScriptCompiler.process = function process(opcodes, meta) {
var compiler = new JavaScriptCompiler(opcodes, meta);
return compiler.process();
};
JavaScriptCompiler.prototype.process = function process() {
var _this = this;
this.opcodes.forEach(function (_ref) {
var opcode = _ref[0];
var args = _ref.slice(1);
if (!_this[opcode]) {
throw new Error('unimplemented ' + opcode + ' on JavaScriptCompiler');
}
_this[opcode].apply(_this, args);
});
return this.template;
};
/// Nesting
JavaScriptCompiler.prototype.startBlock = function startBlock(_ref2) {
var program = _ref2[0];
var block = new Block();
block.positionals = program.blockParams;
this.blocks.push(block);
};
JavaScriptCompiler.prototype.endBlock = function endBlock() {
var template = this.template;
var blocks = this.blocks;
template.block.blocks.push(blocks.pop().toJSON());
};
JavaScriptCompiler.prototype.startProgram = function startProgram() {
this.blocks.push(this.template.block);
};
JavaScriptCompiler.prototype.endProgram = function endProgram() {};
/// Statements
JavaScriptCompiler.prototype.text = function text(content) {
this.push([_glimmerWireFormat.Ops.Text, content]);
};
JavaScriptCompiler.prototype.append = function append(trusted) {
this.push([_glimmerWireFormat.Ops.Append, this.popValue(), trusted]);
};
JavaScriptCompiler.prototype.comment = function comment(value) {
this.push([_glimmerWireFormat.Ops.Comment, value]);
};
JavaScriptCompiler.prototype.modifier = function modifier(path) {
var params = this.popValue();
var hash = this.popValue();
this.push([_glimmerWireFormat.Ops.Modifier, path, params, hash]);
};
JavaScriptCompiler.prototype.block = function block(path, template, inverse) {
var params = this.popValue();
var hash = this.popValue();
var blocks = this.template.block.blocks;
_glimmerUtil.assert(typeof template !== 'number' || blocks[template] !== null, 'missing block in the compiler');
_glimmerUtil.assert(typeof inverse !== 'number' || blocks[inverse] !== null, 'missing block in the compiler');
this.push([_glimmerWireFormat.Ops.Block, path, params, hash, blocks[template], blocks[inverse]]);
};
JavaScriptCompiler.prototype.openElement = function openElement(tag, blockParams) {
if (tag.indexOf('-') !== -1) {
this.startComponent(blockParams);
} else {
this.push([_glimmerWireFormat.Ops.OpenElement, tag, blockParams]);
}
};
JavaScriptCompiler.prototype.flushElement = function flushElement() {
this.push([_glimmerWireFormat.Ops.FlushElement]);
};
JavaScriptCompiler.prototype.closeElement = function closeElement(tag) {
if (tag.indexOf('-') !== -1) {
var component = this.endComponent();
this.push([_glimmerWireFormat.Ops.Component, tag, component]);
} else {
this.push([_glimmerWireFormat.Ops.CloseElement]);
}
};
JavaScriptCompiler.prototype.staticAttr = function staticAttr(name, namespace) {
var value = this.popValue();
this.push([_glimmerWireFormat.Ops.StaticAttr, name, value, namespace]);
};
JavaScriptCompiler.prototype.dynamicAttr = function dynamicAttr(name, namespace) {
var value = this.popValue();
this.push([_glimmerWireFormat.Ops.DynamicAttr, name, value, namespace]);
};
JavaScriptCompiler.prototype.trustingAttr = function trustingAttr(name, namespace) {
var value = this.popValue();
this.push([_glimmerWireFormat.Ops.TrustingAttr, name, value, namespace]);
};
JavaScriptCompiler.prototype.staticArg = function staticArg(name) {
var value = this.popValue();
this.push([_glimmerWireFormat.Ops.StaticArg, name.slice(1), value]);
};
JavaScriptCompiler.prototype.dynamicArg = function dynamicArg(name) {
var value = this.popValue();
this.push([_glimmerWireFormat.Ops.DynamicArg, name.slice(1), value]);
};
JavaScriptCompiler.prototype.yield = function _yield(to) {
var params = this.popValue();
this.push([_glimmerWireFormat.Ops.Yield, to, params]);
this.template.block.yields.add(to);
};
JavaScriptCompiler.prototype.debugger = function _debugger() {
this.push([_glimmerWireFormat.Ops.Debugger, null, null]);
};
JavaScriptCompiler.prototype.hasBlock = function hasBlock(name) {
this.pushValue([_glimmerWireFormat.Ops.HasBlock, name]);
this.template.block.yields.add(name);
};
JavaScriptCompiler.prototype.hasBlockParams = function hasBlockParams(name) {
this.pushValue([_glimmerWireFormat.Ops.HasBlockParams, name]);
this.template.block.yields.add(name);
};
JavaScriptCompiler.prototype.partial = function partial() {
var params = this.popValue();
this.push([_glimmerWireFormat.Ops.Partial, params[0]]);
this.template.block.hasPartials = true;
};
/// Expressions
JavaScriptCompiler.prototype.literal = function literal(value) {
if (value === undefined) {
this.pushValue([_glimmerWireFormat.Ops.Undefined]);
} else {
this.pushValue(value);
}
};
JavaScriptCompiler.prototype.unknown = function unknown(path) {
this.pushValue([_glimmerWireFormat.Ops.Unknown, path]);
};
JavaScriptCompiler.prototype.arg = function arg(path) {
this.template.block.named.add(path[0]);
this.pushValue([_glimmerWireFormat.Ops.Arg, path]);
};
JavaScriptCompiler.prototype.get = function get(path) {
this.pushValue([_glimmerWireFormat.Ops.Get, path]);
};
JavaScriptCompiler.prototype.concat = function concat() {
this.pushValue([_glimmerWireFormat.Ops.Concat, this.popValue()]);
};
JavaScriptCompiler.prototype.helper = function helper(path) {
var params = this.popValue();
var hash = this.popValue();
this.pushValue([_glimmerWireFormat.Ops.Helper, path, params, hash]);
};
/// Stack Management Opcodes
JavaScriptCompiler.prototype.startComponent = function startComponent(blockParams) {
var component = new ComponentBlock();
component.positionals = blockParams;
this.blocks.push(component);
};
JavaScriptCompiler.prototype.endComponent = function endComponent() {
var component = this.blocks.pop();
_glimmerUtil.assert(component.type === 'component', "Compiler bug: endComponent() should end a component");
return component.toJSON();
};
JavaScriptCompiler.prototype.prepareArray = function prepareArray(size) {
var values = [];
for (var i = 0; i < size; i++) {
values.push(this.popValue());
}
this.pushValue(values);
};
JavaScriptCompiler.prototype.prepareObject = function prepareObject(size) {
_glimmerUtil.assert(this.values.length >= size, 'Expected ' + size + ' values on the stack, found ' + this.values.length);
var keys = new Array(size);
var values = new Array(size);
for (var i = 0; i < size; i++) {
keys[i] = this.popValue();
values[i] = this.popValue();
}
this.pushValue([keys, values]);
};
/// Utilities
JavaScriptCompiler.prototype.push = function push(args) {
while (args[args.length - 1] === null) {
args.pop();
}
this.blocks.current.push(args);
};
JavaScriptCompiler.prototype.pushValue = function pushValue(val) {
this.values.push(val);
};
JavaScriptCompiler.prototype.popValue = function popValue() {
_glimmerUtil.assert(this.values.length, "No expression found on stack");
return this.values.pop();
};
return JavaScriptCompiler;
})();
function isTrustedValue(value) {
return value.escaped !== undefined && !value.escaped;
}
var TemplateCompiler = (function () {
function TemplateCompiler(options) {
this.templateId = 0;
this.templateIds = [];
this.symbols = null;
this.opcodes = [];
this.includeMeta = false;
this.options = options || {};
}
TemplateCompiler.compile = function compile(options, ast) {
var templateVisitor = new TemplateVisitor();
templateVisitor.visit(ast);
var compiler = new TemplateCompiler(options);
var opcodes = compiler.process(templateVisitor.actions);
return JavaScriptCompiler.process(opcodes, options.meta);
};
TemplateCompiler.prototype.process = function process(actions) {
var _this2 = this;
actions.forEach(function (_ref3) {
var name = _ref3[0];
var args = _ref3.slice(1);
if (!_this2[name]) {
throw new Error('Unimplemented ' + name + ' on TemplateCompiler');
}
_this2[name].apply(_this2, args);
});
return this.opcodes;
};
TemplateCompiler.prototype.startProgram = function startProgram(program) {
this.opcode('startProgram', program, program);
};
TemplateCompiler.prototype.endProgram = function endProgram() {
this.opcode('endProgram', null);
};
TemplateCompiler.prototype.startBlock = function startBlock(program) {
this.symbols = program[0].symbols;
this.templateId++;
this.opcode('startBlock', program, program);
};
TemplateCompiler.prototype.endBlock = function endBlock() {
this.symbols = null;
this.templateIds.push(this.templateId - 1);
this.opcode('endBlock', null);
};
TemplateCompiler.prototype.text = function text(_ref4) {
var action = _ref4[0];
this.opcode('text', action, action.chars);
};
TemplateCompiler.prototype.comment = function comment(_ref5) {
var action = _ref5[0];
this.opcode('comment', action, action.value);
};
TemplateCompiler.prototype.openElement = function openElement(_ref6) {
var action = _ref6[0];
this.opcode('openElement', action, action.tag, action.blockParams);
for (var i = 0; i < action.attributes.length; i++) {
this.attribute([action.attributes[i]]);
}
for (var i = 0; i < action.modifiers.length; i++) {
this.modifier([action.modifiers[i]]);
}
this.opcode('flushElement', null);
};
TemplateCompiler.prototype.closeElement = function closeElement(_ref7) {
var action = _ref7[0];
this.opcode('closeElement', null, action.tag);
};
TemplateCompiler.prototype.attribute = function attribute(_ref8) {
var action = _ref8[0];
var name = action.name;
var value = action.value;
var namespace = _glimmerUtil.getAttrNamespace(name);
var isStatic = this.prepareAttributeValue(value);
if (name.charAt(0) === '@') {
// Arguments
if (isStatic) {
this.opcode('staticArg', action, name);
} else if (action.value.type === 'MustacheStatement') {
this.opcode('dynamicArg', action, name);
} else {
this.opcode('dynamicArg', action, name);
}
} else {
var isTrusting = isTrustedValue(value);
if (isStatic) {
this.opcode('staticAttr', action, name, namespace);
} else if (isTrusting) {
this.opcode('trustingAttr', action, name, namespace);
} else if (action.value.type === 'MustacheStatement') {
this.opcode('dynamicAttr', action, name);
} else {
this.opcode('dynamicAttr', action, name, namespace);
}
}
};
TemplateCompiler.prototype.modifier = function modifier(_ref9) {
var action = _ref9[0];
assertIsSimplePath(action, 'modifier');
var parts = action.path.parts;
this.prepareHelper(action);
this.opcode('modifier', action, parts);
};
TemplateCompiler.prototype.mustache = function mustache(_ref10) {
var action = _ref10[0];
if (isYield(action)) {
var to = assertValidYield(action);
this.yield(to, action);
} else if (isPartial(action)) {
var params = assertValidPartial(action);
this.partial(params, action);
} else if (isDebugger(action)) {
assertValidDebuggerUsage(action);
this.debugger('debugger', action);
} else {
this.mustacheExpression(action);
this.opcode('append', action, !action.escaped);
}
};
TemplateCompiler.prototype.block = function block(_ref11) /*, index, count*/{
var action = _ref11[0];
this.prepareHelper(action);
var templateId = this.templateIds.pop();
var inverseId = action.inverse === null ? null : this.templateIds.pop();
this.opcode('block', action, action.path.parts, templateId, inverseId);
};
/// Internal actions, not found in the original processed actions
TemplateCompiler.prototype.arg = function arg(_ref12) {
var path = _ref12[0];
var parts = path.parts;
this.opcode('arg', path, parts);
};
TemplateCompiler.prototype.mustacheExpression = function mustacheExpression(expr) {
if (isBuiltInHelper(expr)) {
this.builtInHelper(expr);
} else if (isLiteral(expr)) {
this.opcode('literal', expr, expr.path.value);
} else if (isArg(expr)) {
this.arg([expr.path]);
} else if (isHelperInvocation(expr)) {
this.prepareHelper(expr);
this.opcode('helper', expr, expr.path.parts);
} else if (!isSimplePath(expr) || isSelfGet(expr) || isLocalVariable(expr, this.symbols)) {
this.opcode('get', expr, expr.path.parts);
} else {
this.opcode('unknown', expr, expr.path.parts);
}
};
/// Internal Syntax
TemplateCompiler.prototype.yield = function _yield(to, action) {
this.prepareParams(action.params);
this.opcode('yield', action, to);
};
TemplateCompiler.prototype.debugger = function _debugger(name, action) {
this.opcode('debugger', null);
};
TemplateCompiler.prototype.hasBlock = function hasBlock(name, action) {
this.opcode('hasBlock', action, name);
};
TemplateCompiler.prototype.hasBlockParams = function hasBlockParams(name, action) {
this.opcode('hasBlockParams', action, name);
};
TemplateCompiler.prototype.partial = function partial(params, action) {
this.prepareParams(action.params);
this.opcode('partial', action);
};
TemplateCompiler.prototype.builtInHelper = function builtInHelper(expr) {
if (isHasBlock(expr)) {
var _name = assertValidHasBlockUsage(expr.path.original, expr);
this.hasBlock(_name, expr);
} else if (isHasBlockParams(expr)) {
var _name2 = assertValidHasBlockUsage(expr.path.original, expr);
this.hasBlockParams(_name2, expr);
}
};
/// Expressions, invoked recursively from prepareParams and prepareHash
TemplateCompiler.prototype.SubExpression = function SubExpression(expr) {
if (isBuiltInHelper(expr)) {
this.builtInHelper(expr);
} else {
this.prepareHelper(expr);
this.opcode('helper', expr, expr.path.parts);
}
};
TemplateCompiler.prototype.PathExpression = function PathExpression(expr) {
if (expr.data) {
this.arg([expr]);
} else {
this.opcode('get', expr, expr.parts);
}
};
TemplateCompiler.prototype.StringLiteral = function StringLiteral(action) {
this.opcode('literal', null, action.value);
};
TemplateCompiler.prototype.BooleanLiteral = function BooleanLiteral(action) {
this.opcode('literal', null, action.value);
};
TemplateCompiler.prototype.NumberLiteral = function NumberLiteral(action) {
this.opcode('literal', null, action.value);
};
TemplateCompiler.prototype.NullLiteral = function NullLiteral(action) {
this.opcode('literal', null, action.value);
};
TemplateCompiler.prototype.UndefinedLiteral = function UndefinedLiteral(action) {
this.opcode('literal', null, action.value);
};
/// Utilities
TemplateCompiler.prototype.opcode = function opcode(name, action) {
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
var opcode = [name].concat(args);
if (this.includeMeta && action) {
opcode.push(this.meta(action));
}
this.opcodes.push(opcode);
};
TemplateCompiler.prototype.prepareHelper = function prepareHelper(expr) {
assertIsSimplePath(expr, 'helper');
var params = expr.params;
var hash = expr.hash;
this.prepareHash(hash);
this.prepareParams(params);
};
TemplateCompiler.prototype.preparePath = function preparePath(path) {
this.opcode('literal', path, path.parts);
};
TemplateCompiler.prototype.prepareParams = function prepareParams(params) {
if (!params.length) {
this.opcode('literal', null, null);
return;
}
for (var i = params.length - 1; i >= 0; i--) {
var param = params[i];
_glimmerUtil.assert(this[param.type], 'Unimplemented ' + param.type + ' on TemplateCompiler');
this[param.type](param);
}
this.opcode('prepareArray', null, params.length);
};
TemplateCompiler.prototype.prepareHash = function prepareHash(hash) {
var pairs = hash.pairs;
if (!pairs.length) {
this.opcode('literal', null, null);
return;
}
for (var i = pairs.length - 1; i >= 0; i--) {
var _pairs$i = pairs[i];
var key = _pairs$i.key;
var value = _pairs$i.value;
_glimmerUtil.assert(this[value.type], 'Unimplemented ' + value.type + ' on TemplateCompiler');
this[value.type](value);
this.opcode('literal', null, key);
}
this.opcode('prepareObject', null, pairs.length);
};
TemplateCompiler.prototype.prepareAttributeValue = function prepareAttributeValue(value) {
// returns the static value if the value is static
switch (value.type) {
case 'TextNode':
this.opcode('literal', value, value.chars);
return true;
case 'MustacheStatement':
this.attributeMustache([value]);
return false;
case 'ConcatStatement':
this.prepareConcatParts(value.parts);
this.opcode('concat', value);
return false;
}
};
TemplateCompiler.prototype.prepareConcatParts = function prepareConcatParts(parts) {
for (var i = parts.length - 1; i >= 0; i--) {
var part = parts[i];
if (part.type === 'MustacheStatement') {
this.attributeMustache([part]);
} else if (part.type === 'TextNode') {
this.opcode('literal', null, part.chars);
}
}
this.opcode('prepareArray', null, parts.length);
};
TemplateCompiler.prototype.attributeMustache = function attributeMustache(_ref13) {
var action = _ref13[0];
this.mustacheExpression(action);
};
TemplateCompiler.prototype.meta = function meta(node) {
var loc = node.loc;
if (!loc) {
return [];
}
var source = loc.source;
var start = loc.start;
var end = loc.end;
return ['loc', [source || null, [start.line, start.column], [end.line, end.column]]];
};
return TemplateCompiler;
})();
function isHelperInvocation(mustache) {
return mustache.params && mustache.params.length > 0 || mustache.hash && mustache.hash.pairs.length > 0;
}
function isSimplePath(mustache) {
var parts = mustache.path.parts;
return parts.length === 1;
}
function isSelfGet(mustache) {
var parts = mustache.path.parts;
return parts[0] === null;
}
function isLocalVariable(mustache, symbols) {
var parts = mustache.path.parts;
return parts.length === 1 && symbols && symbols.hasLocalVariable(parts[0]);
}
function isYield(_ref14) {
var path = _ref14.path;
return path.original === 'yield';
}
function isPartial(_ref15) {
var path = _ref15.path;
return path.original === 'partial';
}
function isDebugger(_ref16) {
var path = _ref16.path;
return path.original === 'debugger';
}
function isArg(_ref17) {
var path = _ref17.path;
return path.data;
}
function isLiteral(_ref18) {
var path = _ref18.path;
return path.type === 'StringLiteral' || path.type === 'BooleanLiteral' || path.type === 'NumberLiteral' || path.type === 'NullLiteral' || path.type === 'UndefinedLiteral';
}
function isHasBlock(_ref19) {
var path = _ref19.path;
return path.original === 'has-block';
}
function assertIsSimplePath(expr, context) {
if (!isSimplePath(expr)) {
var original = expr.path.original;
var line = expr.loc.start.line;
throw new Error('`' + original + '` is not a valid name for a ' + context + ' on line ' + line + '.');
}
}
function isHasBlockParams(_ref20) {
var path = _ref20.path;
return path.original === 'has-block-params';
}
function isBuiltInHelper(expr) {
return isHasBlock(expr) || isHasBlockParams(expr);
}
function assertValidYield(_ref21) {
var hash = _ref21.hash;
var pairs = hash.pairs;
if (pairs.length === 1 && pairs[0].key !== 'to' || pairs.length > 1) {
throw new Error('yield only takes a single named argument: \'to\'');
} else if (pairs.length === 1 && pairs[0].value.type !== 'StringLiteral') {
throw new Error('you can only yield to a literal value');
} else if (pairs.length === 0) {
return 'default';
} else {
return pairs[0].value.value;
}
}
function assertValidPartial(_ref22) {
var params = _ref22.params;
var hash = _ref22.hash;
var escaped = _ref22.escaped;
var loc = _ref22.loc;
if (params && params.length !== 1) {
throw new Error('Partial found with no arguments. You must specify a template name. (on line ' + loc.start.line + ')');
} else if (hash && hash.pairs.length > 0) {
throw new Error('partial does not take any named arguments (on line ' + loc.start.line + ')');
} else if (!escaped) {
throw new Error('{{{partial ...}}} is not supported, please use {{partial ...}} instead (on line ' + loc.start.line + ')');
}
return params;
}
function assertValidHasBlockUsage(type, _ref23) {
var params = _ref23.params;
var hash = _ref23.hash;
var loc = _ref23.loc;
if (hash && hash.pairs.length > 0) {
throw new Error(type + ' does not take any named arguments');
}
if (params.length === 0) {
return 'default';
} else if (params.length === 1) {
if (params[0].type === 'StringLiteral') {
return params[0].value;
} else {
throw new Error('you can only yield to a literal value (on line ' + loc.start.line + ')');
}
} else {
throw new Error(type + ' only takes a single positional argument (on line ' + loc.start.line + ')');
}
}
function assertValidDebuggerUsage(_ref24) {
var params = _ref24.params;
var hash = _ref24.hash;
if (hash && hash.pairs.length > 0) {
throw new Error('debugger does not take any named arguments');
}
if (params.length === 0) {
return 'default';
} else {
throw new Error('debugger does not take any positional arguments');
}
}
var defaultId = (function () {
var idFn = undefined;
return function () {
if (!idFn) {
if (typeof require === 'function') {
try {
(function () {
/* tslint:disable:no-require-imports */
var crypto = require('crypto');
/* tslint:enable:no-require-imports */
idFn = function (src) {
var hash = crypto.createHash('sha1');
hash.update(src, 'utf8');
// trim to 6 bytes of data (2^48 - 1)
return hash.digest('base64').substring(0, 8);
};
idFn("test");
})();
} catch (e) {
idFn = null;
}
}
if (!idFn) {
idFn = function () {
return null;
};
}
}
return idFn;
};
})();
function precompile(string, options) {
var opts = options || {
id: defaultId(),
meta: {}
};
var ast = _glimmerSyntax.preprocess(string, opts);
var _TemplateCompiler$compile = TemplateCompiler.compile(opts, ast);
var block = _TemplateCompiler$compile.block;
var meta = _TemplateCompiler$compile.meta;
var idFn = opts.id || defaultId();
var blockJSON = JSON.stringify(block.toJSON());
var templateJSONObject = {
id: idFn(JSON.stringify(meta) + blockJSON),
block: blockJSON,
meta: meta
};
// JSON is javascript
return JSON.stringify(templateJSONObject);
}
exports.precompile = precompile;
exports.TemplateVisitor = TemplateVisitor;
});
enifed("@glimmer/reference", ["exports", "@glimmer/util"], function (exports, _glimmerUtil) {
"use strict";
var CONSTANT = 0;
var INITIAL = 1;
var VOLATILE = NaN;
var RevisionTag = (function () {
function RevisionTag() {}
RevisionTag.prototype.validate = function validate(snapshot) {
return this.value() === snapshot;
};
return RevisionTag;
})();
var $REVISION = INITIAL;
var DirtyableTag = (function (_RevisionTag) {
babelHelpers.inherits(DirtyableTag, _RevisionTag);
function DirtyableTag() {
var revision = arguments.length <= 0 || arguments[0] === undefined ? $REVISION : arguments[0];
_RevisionTag.call(this);
this.revision = revision;
}
DirtyableTag.prototype.value = function value() {
return this.revision;
};
DirtyableTag.prototype.dirty = function dirty() {
this.revision = ++$REVISION;
};
return DirtyableTag;
})(RevisionTag);
function combineTagged(tagged) {
var optimized = [];
for (var i = 0, l = tagged.length; i < l; i++) {
var tag = tagged[i].tag;
if (tag === VOLATILE_TAG) return VOLATILE_TAG;
if (tag === CONSTANT_TAG) continue;
optimized.push(tag);
}
return _combine(optimized);
}
function combineSlice(slice) {
var optimized = [];
var node = slice.head();
while (node !== null) {
var tag = node.tag;
if (tag === VOLATILE_TAG) return VOLATILE_TAG;
if (tag !== CONSTANT_TAG) optimized.push(tag);
node = slice.nextNode(node);
}
return _combine(optimized);
}
function combine(tags) {
var optimized = [];
for (var i = 0, l = tags.length; i < l; i++) {
var tag = tags[i];
if (tag === VOLATILE_TAG) return VOLATILE_TAG;
if (tag === CONSTANT_TAG) continue;
optimized.push(tag);
}
return _combine(optimized);
}
function _combine(tags) {
switch (tags.length) {
case 0:
return CONSTANT_TAG;
case 1:
return tags[0];
case 2:
return new TagsPair(tags[0], tags[1]);
default:
return new TagsCombinator(tags);
}
;
}
var CachedTag = (function (_RevisionTag2) {
babelHelpers.inherits(CachedTag, _RevisionTag2);
function CachedTag() {
_RevisionTag2.apply(this, arguments);
this.lastChecked = null;
this.lastValue = null;
}
CachedTag.prototype.value = function value() {
var lastChecked = this.lastChecked;
var lastValue = this.lastValue;
if (lastChecked !== $REVISION) {
this.lastChecked = $REVISION;
this.lastValue = lastValue = this.compute();
}
return this.lastValue;
};
CachedTag.prototype.invalidate = function invalidate() {
this.lastChecked = null;
};
return CachedTag;
})(RevisionTag);
var TagsPair = (function (_CachedTag) {
babelHelpers.inherits(TagsPair, _CachedTag);
function TagsPair(first, second) {
_CachedTag.call(this);
this.fir