本文整理汇总了TypeScript中@aurelia/jit.IAttributeParser.parse方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IAttributeParser.parse方法的具体用法?TypeScript IAttributeParser.parse怎么用?TypeScript IAttributeParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@aurelia/jit.IAttributeParser
的用法示例。
在下文中一共展示了IAttributeParser.parse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: bindLetElement
private bindLetElement(parentManifest: IElementSymbol, node: HTMLElement): void {
const symbol = new LetElementSymbol(this.dom, node);
parentManifest.childNodes.push(symbol);
const attributes = node.attributes;
let i = 0;
while (i < attributes.length) {
const attr = attributes[i];
if (attr.name === 'to-view-model') {
node.removeAttribute('to-view-model');
symbol.toViewModel = true;
continue;
}
const attrSyntax = this.attrParser.parse(attr.name, attr.value);
const command = this.resources.getBindingCommand(attrSyntax);
const bindingType = command === null ? BindingType.Interpolation : command.bindingType;
const expr = this.exprParser.parse(attrSyntax.rawValue, bindingType);
const to = PLATFORM.camelCase(attrSyntax.target);
const info = new BindableInfo(to, BindingMode.toView);
symbol.bindings.push(new BindingSymbol(command, info, expr, attrSyntax.rawValue, to));
++i;
}
node.parentNode.replaceChild(symbol.marker as Node, node);
}
示例2: bind
public bind(node: HTMLTemplateElement): PlainElementSymbol {
if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bind', slice.call(arguments)); }
if (Profiler.enabled) { enter(); }
const surrogateSave = this.surrogate;
const parentManifestRootSave = this.parentManifestRoot;
const manifestRootSave = this.manifestRoot;
const manifestSave = this.manifest;
const manifest = this.surrogate = this.manifest = new PlainElementSymbol(node);
const attributes = node.attributes;
let i = 0;
while (i < attributes.length) {
const attr = attributes[i];
const attrSyntax = this.attrParser.parse(attr.name, attr.value);
if (invalidSurrogateAttribute[attrSyntax.target] === true) {
if (Profiler.enabled) { leave(); }
throw new Error(`Invalid surrogate attribute: ${attrSyntax.target}`);
// TODO: use reporter
}
const attrInfo = this.resources.getAttributeInfo(attrSyntax);
if (attrInfo === null) {
this.bindPlainAttribute(attrSyntax, attr);
} else if (attrInfo.isTemplateController) {
if (Profiler.enabled) { leave(); }
throw new Error('Cannot have template controller on surrogate element.');
// TODO: use reporter
} else {
this.bindCustomAttribute(attrSyntax, attrInfo);
}
++i;
}
this.bindChildNodes(node);
this.surrogate = surrogateSave;
this.parentManifestRoot = parentManifestRootSave;
this.manifestRoot = manifestRootSave;
this.manifest = manifestSave;
if (Profiler.enabled) { leave(); }
if (Tracer.enabled) { Tracer.leave(); }
return manifest;
}
示例3: bindMultiAttribute
private bindMultiAttribute(symbol: IResourceAttributeSymbol, attrInfo: AttrInfo, value: string): void {
if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bindMultiAttribute', slice.call(arguments)); }
const attributes = parseMultiAttributeBinding(value);
let attr: IAttrLike;
for (let i = 0, ii = attributes.length; i < ii; ++i) {
attr = attributes[i];
const attrSyntax = this.attrParser.parse(attr.name, attr.value);
const command = this.resources.getBindingCommand(attrSyntax);
const bindingType = command === null ? BindingType.Interpolation : command.bindingType;
const expr = this.exprParser.parse(attrSyntax.rawValue, bindingType);
let bindable = attrInfo.bindables[attrSyntax.target];
if (bindable === undefined) {
// everything in a dynamicOptions expression must be used, so if it's not a bindable then we create one on the spot
bindable = attrInfo.bindables[attrSyntax.target] = new BindableInfo(attrSyntax.target, BindingMode.toView);
}
symbol.bindings.push(new BindingSymbol(command, bindable, expr, attrSyntax.rawValue, attrSyntax.target));
}
if (Tracer.enabled) { Tracer.leave(); }
}
示例4: bindAttributes
private bindAttributes(node: HTMLTemplateElement | HTMLElement, parentManifest: IElementSymbol): void {
if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bindAttributes', slice.call(arguments)); }
const { parentManifestRoot, manifestRoot, manifest } = this;
// This is the top-level symbol for the current depth.
// If there are no template controllers or replace-parts, it is always the manifest itself.
// If there are template controllers, then this will be the outer-most TemplateControllerSymbol.
let manifestProxy: IParentNodeSymbol = manifest;
const replacePart = this.declareReplacePart(node);
let previousController: TemplateControllerSymbol;
let currentController: TemplateControllerSymbol;
const attributes = node.attributes;
let i = 0;
while (i < attributes.length) {
const attr = attributes[i];
++i;
if (attributesToIgnore[attr.name] === true) {
continue;
}
const attrSyntax = this.attrParser.parse(attr.name, attr.value);
const attrInfo = this.resources.getAttributeInfo(attrSyntax);
if (attrInfo === null) {
// it's not a custom attribute but might be a regular bound attribute or interpolation (it might also be nothing)
this.bindPlainAttribute(attrSyntax, attr);
} else if (attrInfo.isTemplateController) {
// the manifest is wrapped by the inner-most template controller (if there are multiple on the same element)
// so keep setting manifest.templateController to the latest template controller we find
currentController = manifest.templateController = this.declareTemplateController(attrSyntax, attrInfo);
// the proxy and the manifest are only identical when we're at the first template controller (since the controller
// is assigned to the proxy), so this evaluates to true at most once per node
if (manifestProxy === manifest) {
currentController.template = manifest;
manifestProxy = currentController;
} else {
currentController.templateController = previousController;
currentController.template = previousController.template;
previousController.template = currentController;
}
previousController = currentController;
} else {
// a regular custom attribute
this.bindCustomAttribute(attrSyntax, attrInfo);
}
}
processTemplateControllers(this.dom, manifestProxy, manifest);
if (replacePart === null) {
// the proxy is either the manifest itself or the outer-most controller; add it directly to the parent
parentManifest.childNodes.push(manifestProxy);
} else {
// there is a replace-part attribute on this node, so add it to the parts collection of the manifestRoot
// instead of to the childNodes
replacePart.parent = parentManifest;
replacePart.template = manifestProxy;
// if the current manifest is also the manifestRoot, it means the replace-part sits on a custom
// element, so add the part to the parent wrapping custom element instead
const partOwner = manifest === manifestRoot ? parentManifestRoot : manifestRoot;
partOwner.parts.push(replacePart);
processReplacePart(this.dom, replacePart, manifestProxy);
}
if (Tracer.enabled) { Tracer.leave(); }
}