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