UNPKG

3.48 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4exports.REMOVE_BABEL_WORKAROUND = {
5 suggestionCode: 'DS001',
6 message: 'Remove Babel/TypeScript constructor workaround'
7};
8exports.REMOVE_ARRAY_FROM = {
9 suggestionCode: 'DS101',
10 message: 'Remove unnecessary use of Array.from'
11};
12exports.CLEAN_UP_IMPLICIT_RETURNS = {
13 suggestionCode: 'DS102',
14 message: 'Remove unnecessary code created because of implicit returns'
15};
16exports.REMOVE_GUARD = {
17 suggestionCode: 'DS103',
18 message: 'Rewrite code to no longer use __guard__'
19};
20exports.AVOID_INLINE_ASSIGNMENTS = {
21 suggestionCode: 'DS104',
22 message: 'Avoid inline assignments'
23};
24exports.SIMPLIFY_COMPLEX_ASSIGNMENTS = {
25 suggestionCode: 'DS201',
26 message: 'Simplify complex destructure assignments'
27};
28exports.SIMPLIFY_DYNAMIC_RANGE_LOOPS = {
29 suggestionCode: 'DS202',
30 message: 'Simplify dynamic range loops'
31};
32exports.CLEAN_UP_FOR_OWN_LOOPS = {
33 suggestionCode: 'DS203',
34 message: 'Remove `|| {}` from converted for-own loops'
35};
36exports.FIX_INCLUDES_EVALUATION_ORDER = {
37 suggestionCode: 'DS204',
38 message: 'Change includes calls to have a more natural evaluation order'
39};
40exports.AVOID_IIFES = {
41 suggestionCode: 'DS205',
42 message: 'Consider reworking code to avoid use of IIFEs'
43};
44exports.AVOID_INITCLASS = {
45 suggestionCode: 'DS206',
46 message: 'Consider reworking classes to avoid initClass'
47};
48exports.SHORTEN_NULL_CHECKS = {
49 suggestionCode: 'DS207',
50 message: 'Consider shorter variations of null checks'
51};
52exports.AVOID_TOP_LEVEL_THIS = {
53 suggestionCode: 'DS208',
54 message: 'Avoid top-level this'
55};
56exports.AVOID_TOP_LEVEL_RETURN = {
57 suggestionCode: 'DS209',
58 message: 'Avoid top-level return'
59};
60function mergeSuggestions(suggestions) {
61 var e_1, _a;
62 var suggestionsByCode = {};
63 try {
64 for (var suggestions_1 = tslib_1.__values(suggestions), suggestions_1_1 = suggestions_1.next(); !suggestions_1_1.done; suggestions_1_1 = suggestions_1.next()) {
65 var suggestion = suggestions_1_1.value;
66 suggestionsByCode[suggestion.suggestionCode] = suggestion;
67 }
68 }
69 catch (e_1_1) { e_1 = { error: e_1_1 }; }
70 finally {
71 try {
72 if (suggestions_1_1 && !suggestions_1_1.done && (_a = suggestions_1.return)) _a.call(suggestions_1);
73 }
74 finally { if (e_1) throw e_1.error; }
75 }
76 return Object.keys(suggestionsByCode)
77 .sort()
78 .map(function (code) { return suggestionsByCode[code]; });
79}
80exports.mergeSuggestions = mergeSuggestions;
81function prependSuggestionComment(code, suggestions) {
82 if (suggestions.length === 0) {
83 return code;
84 }
85 var commentLines = tslib_1.__spread([
86 '/*',
87 ' * decaffeinate suggestions:'
88 ], suggestions.map(function (_a) {
89 var suggestionCode = _a.suggestionCode, message = _a.message;
90 return " * " + suggestionCode + ": " + message;
91 }), [
92 ' * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md',
93 ' */'
94 ]);
95 var codeLines = code.split('\n');
96 if (codeLines[0].startsWith('#!')) {
97 return tslib_1.__spread([codeLines[0]], commentLines, codeLines.slice(1)).join('\n');
98 }
99 else {
100 return tslib_1.__spread(commentLines, codeLines).join('\n');
101 }
102}
103exports.prependSuggestionComment = prependSuggestionComment;