MCPcopy Create free account
hub / github.com/nodejs/node / applyRuleEdits

Function applyRuleEdits

test/fixtures/snapshot/typescript.js:147891–147936  ·  view source on GitHub ↗
(rule, previousRange, previousStartLine, currentRange, currentStartLine)

Source from the content-addressed store, hash-verified

147889 }
147890 }
147891 function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) {
147892 var onLaterLine = currentStartLine !== previousStartLine;
147893 switch (rule.action) {
147894 case 1 /* RuleAction.StopProcessingSpaceActions */:
147895 // no action required
147896 return 0 /* LineAction.None */;
147897 case 16 /* RuleAction.DeleteSpace */:
147898 if (previousRange.end !== currentRange.pos) {
147899 // delete characters starting from t1.end up to t2.pos exclusive
147900 recordDelete(previousRange.end, currentRange.pos - previousRange.end);
147901 return onLaterLine ? 2 /* LineAction.LineRemoved */ : 0 /* LineAction.None */;
147902 }
147903 break;
147904 case 32 /* RuleAction.DeleteToken */:
147905 recordDelete(previousRange.pos, previousRange.end - previousRange.pos);
147906 break;
147907 case 8 /* RuleAction.InsertNewLine */:
147908 // exit early if we on different lines and rule cannot change number of newlines
147909 // if line1 and line2 are on subsequent lines then no edits are required - ok to exit
147910 // if line1 and line2 are separated with more than one newline - ok to exit since we cannot delete extra new lines
147911 if (rule.flags !== 1 /* RuleFlags.CanDeleteNewLines */ && previousStartLine !== currentStartLine) {
147912 return 0 /* LineAction.None */;
147913 }
147914 // edit should not be applied if we have one line feed between elements
147915 var lineDelta = currentStartLine - previousStartLine;
147916 if (lineDelta !== 1) {
147917 recordReplace(previousRange.end, currentRange.pos - previousRange.end, ts.getNewLineOrDefaultFromHost(host, options));
147918 return onLaterLine ? 0 /* LineAction.None */ : 1 /* LineAction.LineAdded */;
147919 }
147920 break;
147921 case 4 /* RuleAction.InsertSpace */:
147922 // exit early if we on different lines and rule cannot change number of newlines
147923 if (rule.flags !== 1 /* RuleFlags.CanDeleteNewLines */ && previousStartLine !== currentStartLine) {
147924 return 0 /* LineAction.None */;
147925 }
147926 var posDelta = currentRange.pos - previousRange.end;
147927 if (posDelta !== 1 || sourceFile.text.charCodeAt(previousRange.end) !== 32 /* CharacterCodes.space */) {
147928 recordReplace(previousRange.end, currentRange.pos - previousRange.end, " ");
147929 return onLaterLine ? 2 /* LineAction.LineRemoved */ : 0 /* LineAction.None */;
147930 }
147931 break;
147932 case 64 /* RuleAction.InsertTrailingSemicolon */:
147933 recordInsert(previousRange.end, ";");
147934 }
147935 return 0 /* LineAction.None */;
147936 }
147937 }
147938 var LineAction;
147939 (function (LineAction) {

Callers 1

processPairFunction · 0.85

Calls 3

recordDeleteFunction · 0.85
recordReplaceFunction · 0.85
recordInsertFunction · 0.85

Tested by

no test coverage detected