MCPcopy
hub / github.com/ampproject/amphtml / stripComments

Function stripComments

build-system/test-configs/forbidden-terms.js:1073–1088  ·  view source on GitHub ↗

* Strip Comments * @param {string} contents * @return {string}

(contents)

Source from the content-addressed store, hash-verified

1071 * @return {string}
1072 */
1073function stripComments(contents) {
1074 // Multi-line comments
1075 contents = contents.replace(/\/\*(?!.*\*\/)(.|\n)*?\*\//g, function (match) {
1076 // Preserve the newlines
1077 const newlines = [];
1078 for (let i = 0; i < match.length; i++) {
1079 if (match[i] === '\n') {
1080 newlines.push('\n');
1081 }
1082 }
1083 return newlines.join('');
1084 });
1085 // Single line comments either on its own line or following a space,
1086 // semi-colon, or closing brace
1087 return contents.replace(/( |}|;|^) *\/\/.*/gm, '$1');
1088}
1089
1090/**
1091 * Collects any forbidden terms (regex patterns) in the contents of a file,

Callers 1

matchForbiddenTermsFunction · 0.85

Calls 2

replaceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected