Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`${input} -> ${expected}`, function () {
const actual = camelCase(input);
assert.strictEqual(actual, expected, `actual`);
assert.strictEqual(camelCase(input), actual, `camelCase(input)`); // verify via code coverage report that cache is being hit
});
}
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-binding-context') {
node.removeAttribute('to-binding-context');
symbol.toBindingContext = true;
continue;
}
const attrSyntax = this.attrParser.parse(attr.name, attr.value);
const command = this.resources.getBindingCommand(attrSyntax, false);
const bindingType = command === null ? 2048 /* Interpolation */ : command.bindingType;
const expr = this.exprParser.parse(attrSyntax.rawValue, bindingType);
const to = 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, node);
}
bindAttributes(node, parentManifest, surrogate, manifest, manifestRoot, parentManifestRoot, partName) {
private bindPlainAttribute(attrSyntax: AttrSyntax, attr: Attr): void {
const command = this.resources.getBindingCommand(attrSyntax, false);
const bindingType = command == null ? BindingType.Interpolation : command.bindingType;
const manifest = this.manifest!;
const attrTarget = attrSyntax.target;
const attrRawValue = attrSyntax.rawValue;
let expr: AnyBindingExpression;
if (
attrRawValue.length === 0
&& (bindingType & BindingType.BindCommand | BindingType.OneTimeCommand | BindingType.ToViewCommand | BindingType.TwoWayCommand) > 0
) {
if ((bindingType & BindingType.BindCommand | BindingType.OneTimeCommand | BindingType.ToViewCommand | BindingType.TwoWayCommand) > 0) {
// Default to the name of the attr for empty binding commands
expr = this.exprParser.parse(camelCase(attrTarget), bindingType);
} else {
return;
}
} else {
expr = this.exprParser.parse(attrRawValue, bindingType);
}
if (manifest.flags & SymbolFlags.isCustomElement) {
const bindable = (manifest as CustomElementSymbol).bindables[attrTarget];
if (bindable != null) {
// if the attribute name matches a bindable property name, add it regardless of whether it's a command, interpolation, or just a plain string;
// the template compiler will translate it to the correct instruction
(manifest as CustomElementSymbol).bindings.push(new BindingSymbol(command, bindable, expr, attrRawValue, attrTarget));
manifest.isTarget = true;
} else if (expr != null) {
// if it does not map to a bindable, only add it if we were able to parse an expression (either a command or interpolation)
ch = value.charCodeAt(i);
if (ch === 92 /* Backslash */) {
++i;
// Ignore whatever comes next because it's escaped
}
else if (ch === 59 /* Semicolon */) {
attrValue = value.slice(start, i);
break;
}
}
if (attrValue === void 0) {
// No semicolon found, so just grab the rest of the value
attrValue = value.slice(start);
}
const attrSyntax = this.attrParser.parse(attrName, attrValue);
const attrTarget = camelCase(attrSyntax.target);
const command = this.resources.getBindingCommand(attrSyntax, false);
const bindingType = command === null ? 2048 /* Interpolation */ : command.bindingType;
const expr = this.exprParser.parse(attrValue, bindingType);
let bindable = bindables[attrTarget];
if (bindable === undefined) {
// everything in a multi-bindings expression must be used,
// so if it's not a bindable then we create one on the spot
bindable = bindables[attrTarget] = new BindableInfo(attrTarget, BindingMode.toView);
}
symbol.bindings.push(new BindingSymbol(command, bindable, expr, attrValue, attrTarget));
// Skip whitespace after semicolon
while (i < valueLength && value.charCodeAt(++i) <= 32 /* Space */)
;
start = i;
attrName = void 0;
attrValue = void 0;
export function nameConvention(className: string): INameConvention {
const m = className.match(/^(.+?)(CustomAttribute|ValueConverter|BindingBehavior|BindingCommand)?$/);
if (!m) {
throw new Error('No convention found for class name ' + className);
}
const bareName = m[1];
const type = (m[2] ? camelCase(m[2]) : 'customElement') as ResourceType;
return {
name: normalizedName(bareName, type),
type
};
}
export function getTarget(binding: PlainAttributeSymbol | BindingSymbol, makeCamelCase: boolean): string {
if (binding.flags & SymbolFlags.isBinding) {
return (binding as BindingSymbol).bindable.propName;
} else if (makeCamelCase) {
return camelCase((binding as PlainAttributeSymbol).syntax.target);
} else {
return (binding as PlainAttributeSymbol).syntax.target;
}
}
function normalizedName(name, type) {
if (type === 'valueConverter' || type === 'bindingBehavior') {
return camelCase(name);
}
return kebabCase(name);
}
//# sourceMappingURL=name-convention.js.map
function normalizedName(name: string, type: ResourceType) {
if (type === 'valueConverter' || type === 'bindingBehavior') {
return camelCase(name);
}
return kebabCase(name);
}