<commit_before>import {Metadata, Origin, ResourceType} from 'aurelia-metadata';
import {ObserverLocator} from 'aurelia-binding';
import {TaskQueue} from 'aurelia-task-queue';
import {ViewStrategy} from './view-strategy';
import {ViewEngine} from './view-engine';
import {ContentSelector} from './content-selector';
import {hyphenate} from './util';
import {BindableProperty} from './bindable-property';

var defaultInstruction = { suppressBind:false },
    contentSelectorFactoryOptions = { suppressBind:true },
    hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

export class HtmlBehaviorResource extends ResourceType {
  constructor(){
    this.elementName = null;
    this.attributeName = null;
    this.liftsContent = false;
    this.targetShadowDOM = false;
    this.skipContentProcessing = false;
    this.usesShadowDOM = false;
    this.childExpression = null;
    this.hasDynamicOptions = false;
    this.properties = [];
    this.attributes = {};
  }

  static convention(name, existing){
    var behavior;

    if(name.endsWith('CustomAttribute')){
      behavior = existing || new HtmlBehaviorResource();
      behavior.attributeName = hyphenate(name.substring(0, name.length-15));
    }

    if(name.endsWith('CustomElement')){
      behavior = existing || new HtmlBehaviorResource();
      behavior.elementName = hyphenate(name.substring(0, name.length-13));
    }

    return behavior;
  }

  analyze(container, target){
    var proto = target.prototype,
        properties = this.properties,
        attributeName = this.attributeName,
        i, ii, current;

    this.observerLocator = container.get(ObserverLocator);
    this.taskQueue = container.get(TaskQueue);

    this.target = target;
    this.usesShadowDOM = this.targetShadowDOM && hasShadowDOM;
    this.handlesCreated = ('created' in proto);
    this.handlesBind = ('bind' in proto);
    this.handlesUnbind = ('unbind' in proto);
    this.handlesAttached = ('attached' in proto);
    this.handlesDetached = ('detached' in proto);
    this.apiName = (this.elementName || this.attributeName).replace(/-([a-z])/g, (m, w) => w.toUpperCase());

    if(attributeName !== null){
      if(properties.length === 0){ //default for custom attributes
        new BindableProperty(
          'value',
          'valueChanged' in proto ? 'valueChanged' : null,
          attributeName
        ).registerWith(target, this);
      }

      if(properties.length === 1){ //default for custom attributes
        current = properties[0];
        current.isDynamic = hasDynamicOptions;
        current.defineOn(target, this);<commit_msg>fix(html-behavior): bad dynamic options ref<commit_after>import {Metadata, Origin, ResourceType} from 'aurelia-metadata';
import {ObserverLocator} from 'aurelia-binding';
import {TaskQueue} from 'aurelia-task-queue';
import {ViewStrategy} from './view-strategy';
import {ViewEngine} from './view-engine';
import {ContentSelector} from './content-selector';
import {hyphenate} from './util';
import {BindableProperty} from './bindable-property';

var defaultInstruction = { suppressBind:false },
    contentSelectorFactoryOptions = { suppressBind:true },
    hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

export class HtmlBehaviorResource extends ResourceType {
  constructor(){
    this.elementName = null;
    this.attributeName = null;
    this.liftsContent = false;
    this.targetShadowDOM = false;
    this.skipContentProcessing = false;
    this.usesShadowDOM = false;
    this.childExpression = null;
    this.hasDynamicOptions = false;
    this.properties = [];
    this.attributes = {};
  }

  static convention(name, existing){
    var behavior;

    if(name.endsWith('CustomAttribute')){
      behavior = existing || new HtmlBehaviorResource();
      behavior.attributeName = hyphenate(name.substring(0, name.length-15));
    }

    if(name.endsWith('CustomElement')){
      behavior = existing || new HtmlBehaviorResource();
      behavior.elementName = hyphenate(name.substring(0, name.length-13));
    }

    return behavior;
  }

  analyze(container, target){
    var proto = target.prototype,
        properties = this.properties,
        attributeName = this.attributeName,
        i, ii, current;

    this.observerLocator = container.get(ObserverLocator);
    this.taskQueue = container.get(TaskQueue);

    this.target = target;
    this.usesShadowDOM = this.targetShadowDOM && hasShadowDOM;
    this.handlesCreated = ('created' in proto);
    this.handlesBind = ('bind' in proto);
    this.handlesUnbind = ('unbind' in proto);
    this.handlesAttached = ('attached' in proto);
    this.handlesDetached = ('detached' in proto);
    this.apiName = (this.elementName || this.attributeName).replace(/-([a-z])/g, (m, w) => w.toUpperCase());

    if(attributeName !== null){
      if(properties.length === 0){ //default for custom attributes
        new BindableProperty(
          'value',
          'valueChanged' in proto ? 'valueChanged' : null,
          attributeName
        ).registerWith(target, this);
      }

      if(properties.length === 1){ //default for custom attributes
        current = properties[0];
        current.isDynamic = this.hasDynamicOptions;
        current.defineOn(target, this);
{'fraction_non_alphanumeric': 0.12759870303261492, 'fraction_numerical': 0.003433148960518787, 'mean_word_length': 3.5799126637554584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638686', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1467, 'n_words': 335}