本文整理匯總了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(); }
}