Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(markup, function () {
const ctx = TestContext.createHTMLTestContext();
const { dom, container } = ctx;
container.register(CustomAttribute.define({ name: 'attr', bindables: ['a', 'b', 'c'] }, class {}));
const resources = new ResourceModel(container);
const attrParser = container.get(IAttributeParser);
const exprParser = container.get(IExpressionParser);
const transformer = container.get(IAttrSyntaxTransformer);
const factory = container.get(ITemplateElementFactory);
const sut = new TemplateBinder(dom, resources, attrParser, exprParser, transformer);
const template = factory.createTemplate(markup) as HTMLTemplateElement;
const manifestRoot = sut.bind(template);
const div = manifestRoot.childNodes[0] as PlainElementSymbol;
const { customAttributes } = div;
assert.strictEqual(customAttributes.length, 1, 'customAttributes.length');
const [{ bindings }] = customAttributes;
it.skip(escaped, function () {
const ctx = TestContext.createHTMLTestContext();
const parser = new ctx.DOMParser();
const doc = parser.parseFromString(markup, 'application/xml');
const fakeSurrogate = { firstChild: doc, attributes: [] };
const binder = new TemplateBinder(
ctx.dom,
new ResourceModel(new RuntimeCompilationResources(ctx.container)),
ctx.container.get(IAttributeParser),
ctx.container.get(IExpressionParser),
ctx.container.get(IAttrSyntaxTransformer)
);
const result = binder.bind(fakeSurrogate as any);
assert.strictEqual(result.physicalNode, fakeSurrogate, `result.physicalNode`);
});
}
public compile(dom: IDOM, definition: ITemplateDefinition, descriptions: IResourceDescriptions): TemplateDefinition {
if (Profiler.enabled) { enter(); }
const binder = new TemplateBinder(dom, new ResourceModel(descriptions), this.attrParser, this.exprParser);
const template = definition.template = this.factory.createTemplate(definition.template) as HTMLTemplateElement;
const surrogate = binder.bind(template);
if (definition.instructions === undefined || definition.instructions === (PLATFORM.emptyArray as typeof definition.instructions & typeof PLATFORM.emptyArray)) {
definition.instructions = [];
}
if (surrogate.hasSlots === true) {
definition.hasSlots = true;
}
this.instructionRows = definition.instructions as HTMLInstructionRow[];
this.parts = {};
const attributes = surrogate.attributes;
const len = attributes.length;
if (len > 0) {
let surrogates: ITargetedInstruction[];
compile(dom, definition, descriptions) {
if (Profiler.enabled) {
enter$2();
}
const binder = new TemplateBinder(dom, new ResourceModel(descriptions), this.attrParser, this.exprParser);
const template = definition.template = this.factory.createTemplate(definition.template);
const surrogate = binder.bind(template);
if (definition.instructions === undefined || definition.instructions === PLATFORM.emptyArray) {
definition.instructions = [];
}
if (surrogate.hasSlots === true) {
definition.hasSlots = true;
}
this.instructionRows = definition.instructions;
this.parts = {};
const attributes = surrogate.attributes;
const len = attributes.length;
if (len > 0) {
let surrogates;
if (definition.surrogates === undefined || definition.surrogates === PLATFORM.emptyArray) {
definition.surrogates = Array(len);
public compile(dom: IDOM, definition: ITemplateDefinition, descriptions: IResourceDescriptions): TemplateDefinition {
const binder = new TemplateBinder(
dom,
new ResourceModel(descriptions),
this.attrParser,
this.exprParser,
this.attrSyntaxModifier
);
const template = definition.template = this.factory.createTemplate(definition.template) as HTMLTemplateElement;
const surrogate = binder.bind(template);
if (definition.instructions === undefined || definition.instructions === (PLATFORM.emptyArray as typeof definition.instructions & typeof PLATFORM.emptyArray)) {
definition.instructions = [];
}
if (surrogate.hasSlots === true) {
definition.hasSlots = true;
}
if (definition.scopeParts === void 0 || definition.scopeParts === PLATFORM.emptyArray) {
definition.scopeParts = [];
}