MCPcopy Create free account
hub / github.com/reactjs/react-rails / _renderClassBody

Function _renderClassBody

lib/assets/javascripts/JSXTransformer.js:13850–13932  ·  view source on GitHub ↗

* @param {function} traverse * @param {object} node * @param {array} path * @param {object} state

(traverse, node, path, state)

Source from the content-addressed store, hash-verified

13848 * @param {object} state
13849 */
13850function _renderClassBody(traverse, node, path, state) {
13851 var className = state.className;
13852 var superClass = state.superClass;
13853
13854 // Set up prototype of constructor on same line as `extends` for line-number
13855 // preservation. This relies on function-hoisting if a constructor function is
13856 // defined in the class body.
13857 if (superClass.name) {
13858 // If the super class is an expression, we need to memoize the output of the
13859 // expression into the generated class name variable and use that to refer
13860 // to the super class going forward. Example:
13861 //
13862 // class Foo extends mixin(Bar, Baz) {}
13863 // --transforms to--
13864 // function Foo() {} var ____Class0Blah = mixin(Bar, Baz);
13865 if (superClass.expression !== null) {
13866 utils.append(
13867 'var ' + superClass.name + '=' + superClass.expression + ';',
13868 state
13869 );
13870 }
13871
13872 var keyName = superClass.name + '____Key';
13873 var keyNameDeclarator = '';
13874 if (!utils.identWithinLexicalScope(keyName, state)) {
13875 keyNameDeclarator = 'var ';
13876 declareIdentInLocalScope(keyName, initScopeMetadata(node), state);
13877 }
13878 utils.append(
13879 'for(' + keyNameDeclarator + keyName + ' in ' + superClass.name + '){' +
13880 'if(' + superClass.name + '.hasOwnProperty(' + keyName + ')){' +
13881 className + '[' + keyName + ']=' +
13882 superClass.name + '[' + keyName + '];' +
13883 '}' +
13884 '}',
13885 state
13886 );
13887
13888 var superProtoIdentStr = SUPER_PROTO_IDENT_PREFIX + superClass.name;
13889 if (!utils.identWithinLexicalScope(superProtoIdentStr, state)) {
13890 utils.append(
13891 'var ' + superProtoIdentStr + '=' + superClass.name + '===null?' +
13892 'null:' + superClass.name + '.prototype;',
13893 state
13894 );
13895 declareIdentInLocalScope(superProtoIdentStr, initScopeMetadata(node), state);
13896 }
13897
13898 utils.append(
13899 className + '.prototype=Object.create(' + superProtoIdentStr + ');',
13900 state
13901 );
13902 utils.append(
13903 className + '.prototype.constructor=' + className + ';',
13904 state
13905 );
13906 utils.append(
13907 className + '.__superConstructor__=' + superClass.name + ';',

Callers 2

visitClassDeclarationFunction · 0.85
visitClassExpressionFunction · 0.85

Calls 3

declareIdentInLocalScopeFunction · 0.85
initScopeMetadataFunction · 0.85
traverseFunction · 0.85

Tested by

no test coverage detected