<commit_before>/*
 * Copyright (C) 2013 salesforce.com, inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @class ComponentDef
 *
 * Constructs a new ComponentDef object, which is a component definition.
 * A ComponentDef instance is created as part of Aura initialization.
 *
 * @constructor
 * @protected
 * @export
 */
function InteropComponentDef(config) {
    this.interop          = true;
    this.access           = config.access;
    this.descriptor       = new DefDescriptor(config.descriptor);
    this.dependencies     = config.dependencies;
    this.definition       = config.definition;
    this.moduleName       = config.moduleName;
    this.interopClass     = config.interopClass;
    this.elementName      = this.moduleName;
    this.interopClassName = this.descriptor.getNamespace() + "$" + this.descriptor.getName();
    this.minVersion       = config.minVersion;
    this.attributeDefs    = new AttributeDefSet(config.attributeDefs, this.descriptor.getNamespace());

    if (typeof this.interopClass === 'function') {
        this.interopDef = $A.componentService.moduleEngine['getComponentDef'](this.interopClass);
        this.setupPropAttrMap(this.interopClass['interopMap'], this.interopDef['props']);
    }
}

/**
 * This method cant be initialized @construnction time because we dont have this.interopDef["props"] (window["Engine"]['getComponentDef'](interopClass)) for libraries
 *
 * @param interopMap in 'props' contains a mapping in the form 'prop' => 'attr' ( (lwc name) => (aura name) )
 * @param props
 */
InteropComponentDef.prototype.setupPropAttrMap = function (interopMap, props) {
    var propNames = Object.keys(props);
    var interopPropOverride = interopMap && $A.util.isObject(interopMap['props']) ? interopMap['props'] : {};
    var propName, attrName;

    this.attrNameToPropMap = {};
    this.propNameToAttrMap = {};

    for (var i = 0; i < propNames.length; i++) {
        propName = propNames[i];
        attrName = (
            interopPropOverride[propName] ||
            InteropComponentDef.prototype.DOM_PROPS_TO_AURA_ATTRS[propName] ||
            propName
        );

        this.attrNameToPropMap[attrName] = propName;
        this.propNameToAttrMap[propName] = attrName;
    }
};

// Mapping taken from https://github.com/salesforce/lwc/blob/1ee756b5038c463d7b9fa0d7eace23fcd6acf0c3/packages/lwc-template-compiler/src/parser/constants.ts#L52-L109
InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS = {
    'accesskey': 'accessKey',
    'readonly': 'readOnly',
    'tabindex': 'tabIndex',
    'bgcolor': 'bgColor',
    'colspan': 'colSpan',
    'rowspan': 'rowSpan',
    'contenteditable': 'contentEditable',
    'crossorigin': 'crossOrigin',
    'datetime': 'dateTime',
    'formaction': 'formAction',
    'ismap': 'isMap',
    'maxlength': 'maxLength',
    'minlength': 'minLength',
    'novalidate': 'noValidate',
    'usemap': 'useMap',
    'for': 'htmlFor',

    // Aria
    'aria-autocomplete': 'ariaAutoComplete',
    'aria-checked': 'ariaChecked',
    'aria-current': 'ariaCurrent',
    'aria-disabled': 'ariaDisabled',
    'aria-expanded': 'ariaExpanded',
    'aria-haspopup': 'ariaHasPopUp',
    'aria-hidden': 'ariaHidden',
    'aria-invalid': 'ariaInvalid',
    'aria-label': 'ariaLabel',
    'aria-level': 'ariaLevel',
    'aria-multiline': 'ariaMultiLine',
    'aria-multiselectable': 'ariaMultiSelectable',
    'aria-orientation': 'ariaOrientation',
    'aria-pressed': 'ariaPressed',
    'aria-readonly': 'ariaReadOnly',
    'aria-required': 'ariaRequired',
    'aria-selected': 'ariaSelected',
    'aria-sort': 'ariaSort',
    'aria-valuemax': 'ariaValueMax',
    'aria-valuemin': 'ariaValueMin',
    'aria-valuenow': 'ariaValueNow',
    'aria-valuetext': 'ariaValueText',
    'aria-live': 'ariaLive',
    'aria-relevant': 'ariaRelevant',
    'aria-atomic': 'ariaAtomic',
    'aria-busy': 'ariaBusy',
    'aria-activedescendant': 'ariaActiveDescendant',
    'aria-controls': 'ariaControls',
    'aria-describedby': 'ariaDescribedBy',
    'aria-flowto': 'ariaFlowTo',
    'aria-labelledby': 'ariaLabelledBy',
    'aria-owns': 'ariaOwns',
    'aria-posinset': 'ariaPosInSet',
    'aria-setsize': 'ariaSetSize',

    'aria-colcount': 'ariaColCount',
    'aria-colindex': 'ariaColIndex',
    'aria-details': 'ariaDetails',
    'aria-errormessage': 'ariaErrorMessage',
    'aria-keyshortcuts': 'ariaKeyShortcuts',
    'aria-modal': 'ariaModal',
    'aria-placeholder': 'ariaPlaceholder',
    'aria-roledescription': 'ariaRoleDescription',
    'aria-rowcount': 'ariaRowCount',
    'aria-rowindex': 'ariaRowIndex',
    'aria-rowspan': 'ariaRowSpan'
};

// Invert the (attr => prop) map to (prop => attr) while filtering out
// attribute names that are incompatible with Aura (e.g., aria-*). If we didn't
// filter these out here, users would be able to <x:y aria-checked="mixed"/>
// which is currently not supported in Aura. Side note: data-* attributes are
// supported in Aura, but only on HTML elements.
InteropComponentDef.prototype.DOM_PROPS_TO_AURA_ATTRS = Object.keys(
    InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS
).reduce(function(map, attr) {
    if (attr.indexOf('-') === -1) {
        var prop = InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS[attr];
        map[prop] = attr;
    }
    return map;
}, {});

InteropComponentDef.prototype.hasInit = function() {
   
};

/**
 * Returns a DefDescriptor object.
 *<commit_msg>Update aria attribute list (#2673)<commit_after>/*
 * Copyright (C) 2013 salesforce.com, inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @class ComponentDef
 *
 * Constructs a new ComponentDef object, which is a component definition.
 * A ComponentDef instance is created as part of Aura initialization.
 *
 * @constructor
 * @protected
 * @export
 */
function InteropComponentDef(config) {
    this.interop          = true;
    this.access           = config.access;
    this.descriptor       = new DefDescriptor(config.descriptor);
    this.dependencies     = config.dependencies;
    this.definition       = config.definition;
    this.moduleName       = config.moduleName;
    this.interopClass     = config.interopClass;
    this.elementName      = this.moduleName;
    this.interopClassName = this.descriptor.getNamespace() + "$" + this.descriptor.getName();
    this.minVersion       = config.minVersion;
    this.attributeDefs    = new AttributeDefSet(config.attributeDefs, this.descriptor.getNamespace());

    if (typeof this.interopClass === 'function') {
        this.interopDef = $A.componentService.moduleEngine['getComponentDef'](this.interopClass);
        this.setupPropAttrMap(this.interopClass['interopMap'], this.interopDef['props']);
    }
}

/**
 * This method cant be initialized @construnction time because we dont have this.interopDef["props"] (window["Engine"]['getComponentDef'](interopClass)) for libraries
 *
 * @param interopMap in 'props' contains a mapping in the form 'prop' => 'attr' ( (lwc name) => (aura name) )
 * @param props
 */
InteropComponentDef.prototype.setupPropAttrMap = function (interopMap, props) {
    var propNames = Object.keys(props);
    var interopPropOverride = interopMap && $A.util.isObject(interopMap['props']) ? interopMap['props'] : {};
    var propName, attrName;

    this.attrNameToPropMap = {};
    this.propNameToAttrMap = {};

    for (var i = 0; i < propNames.length; i++) {
        propName = propNames[i];
        attrName = (
            interopPropOverride[propName] ||
            InteropComponentDef.prototype.DOM_PROPS_TO_AURA_ATTRS[propName] ||
            propName
        );

        this.attrNameToPropMap[attrName] = propName;
        this.propNameToAttrMap[propName] = attrName;
    }
};

// Mapping taken from https://github.com/salesforce/lwc/blob/5fd64c2b760d07e1e1f95cdf89d61ff6d9cf6af0/packages/lwc-template-compiler/src/parser/constants.ts#L52-L124
InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS = {
    'accesskey': 'accessKey',
    'readonly': 'readOnly',
    'tabindex': 'tabIndex',
    'bgcolor': 'bgColor',
    'colspan': 'colSpan',
    'rowspan': 'rowSpan',
    'contenteditable': 'contentEditable',
    'crossorigin': 'crossOrigin',
    'datetime': 'dateTime',
    'formaction': 'formAction',
    'ismap': 'isMap',
    'maxlength': 'maxLength',
    'minlength': 'minLength',
    'novalidate': 'noValidate',
    'usemap': 'useMap',
    'for': 'htmlFor',

    'aria-activedescendant': 'ariaActiveDescendant',
    'aria-atomic': 'ariaAtomic',
    'aria-autocomplete': 'ariaAutoComplete',
    'aria-busy': 'ariaBusy',
    'aria-checked': 'ariaChecked',
    'aria-colcount': 'ariaColCount',
    'aria-colindex': 'ariaColIndex',
    'aria-colspan': 'ariaColSpan',
    'aria-controls': 'ariaControls',
    'aria-current': 'ariaCurrent',
    'aria-describedby': 'ariaDescribedBy',
    'aria-details': 'ariaDetails',
    'aria-disabled': 'ariaDisabled',
//  'aria-dropeffect': 'ariaDropEffect', /* Deprecated in ARIA 1.1 */
    'aria-errormessage': 'ariaErrorMessage',
    'aria-expanded': 'ariaExpanded',
    'aria-flowto': 'ariaFlowTo',
//  'aria-grabbed': 'ariaGrabbed', /* Deprecated in ARIA 1.1 */
    'aria-haspopup': 'ariaHasPopup',
    'aria-hidden': 'ariaHidden',
    'aria-invalid': 'ariaInvalid',
    'aria-keyshortcuts': 'ariaKeyShortcuts',
    'aria-label': 'ariaLabel',
    'aria-labelledby': 'ariaLabelledBy',
    'aria-level': 'ariaLevel',
    'aria-live': 'ariaLive',
    'aria-modal': 'ariaModal',
    'aria-multiline': 'ariaMultiLine',
    'aria-multiselectable': 'ariaMultiSelectable',
    'aria-orientation': 'ariaOrientation',
    'aria-owns': 'ariaOwns',
    'aria-placeholder': 'ariaPlaceholder',
    'aria-posinset': 'ariaPosInSet',
    'aria-pressed': 'ariaPressed',
    'aria-readonly': 'ariaReadOnly',
    'aria-relevant': 'ariaRelevant',
    'aria-required': 'ariaRequired',
    'aria-roledescription': 'ariaRoleDescription',
    'aria-rowcount': 'ariaRowCount',
    'aria-rowindex': 'ariaRowIndex',
    'aria-rowspan': 'ariaRowSpan',
    'aria-selected': 'ariaSelected',
    'aria-setsize': 'ariaSetSize',
    'aria-sort': 'ariaSort',
    'aria-valuemax': 'ariaValueMax',
    'aria-valuemin': 'ariaValueMin',
    'aria-valuenow': 'ariaValueNow',
    'aria-valuetext': 'ariaValueText'
};

// Invert the (attr => prop) map to (prop => attr) while filtering out
// attribute names that are incompatible with Aura (e.g., aria-*). If we didn't
// filter these out here, users would be able to <x:y aria-checked="mixed"/>
// which is currently not supported in Aura. Side note: data-* attributes are
// supported in Aura, but only on HTML elements.
InteropComponentDef.prototype.DOM_PROPS_TO_AURA_ATTRS = Object.keys(
    InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS
).reduce(function(map, attr) {
    if (attr.indexOf('-') === -1) {
        var prop = InteropComponentDef.prototype.HTML_ATTRS_TO_DOM_PROPS[attr];
        map[prop] = attr;
    }
    return map;
}, {});

InteropComponentDef.prototype.hasInit = function() {
   
};

/**
 * Returns a DefDescriptor object.
 *
{'fraction_non_alphanumeric': 0.14286896780067876, 'fraction_numerical': 0.006539193775349722, 'mean_word_length': 3.7473477406679763, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4441511', 'n_tokens_mistral': 3859, 'n_tokens_neox': 3778, 'n_words': 847}