MCPcopy Index your code
hub / github.com/ampproject/amphtml / sourceIncludes

Function sourceIncludes

testing/element-v1.js:143–161  ·  view source on GitHub ↗

* Returns `true` if the class's source contains the given substring. * * @param {typeof BaseElement} implClass * @param {string} substring * @return {boolean}

(implClass, substring)

Source from the content-addressed store, hash-verified

141 * @return {boolean}
142 */
143function sourceIncludes(implClass, substring) {
144 const code = [];
145 code.push(implClass.toString());
146 const classProps = Object.getOwnPropertyDescriptors(implClass);
147 for (const k in classProps) {
148 const desc = classProps[k];
149 if (typeof desc.value == 'function') {
150 code.push(desc.value.toString());
151 }
152 }
153 const protoProps = Object.getOwnPropertyDescriptors(implClass.prototype);
154 for (const k in protoProps) {
155 const desc = protoProps[k];
156 if (typeof desc.value == 'function') {
157 code.push(desc.value.toString());
158 }
159 }
160 return code.filter((code) => code.includes(substring)).length > 0;
161}

Callers 1

element-v1.jsFile · 0.85

Calls 3

pushMethod · 0.45
toStringMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected