@tslite/printer 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- // A entrada dos testes deste pacote: reexporta o barril, que é a entrada do pacote (o `exports` do `package.json`). O
2
- // barril avalia os arquivos na ordem do outFile da tag, e um import direto de um arquivo avaliaria os outros noutra
3
- // ordem.
4
- export * from "./_namespaces/ts.js";
package/dist/types.js DELETED
@@ -1,65 +0,0 @@
1
- export var ListFormat;
2
- (function (ListFormat) {
3
- ListFormat[ListFormat["None"] = 0] = "None";
4
- // Line separators
5
- ListFormat[ListFormat["SingleLine"] = 0] = "SingleLine";
6
- ListFormat[ListFormat["MultiLine"] = 1] = "MultiLine";
7
- ListFormat[ListFormat["PreserveLines"] = 2] = "PreserveLines";
8
- ListFormat[ListFormat["LinesMask"] = 3] = "LinesMask";
9
- // Delimiters
10
- ListFormat[ListFormat["NotDelimited"] = 0] = "NotDelimited";
11
- ListFormat[ListFormat["BarDelimited"] = 4] = "BarDelimited";
12
- ListFormat[ListFormat["AmpersandDelimited"] = 8] = "AmpersandDelimited";
13
- ListFormat[ListFormat["CommaDelimited"] = 16] = "CommaDelimited";
14
- ListFormat[ListFormat["DelimitersMask"] = 28] = "DelimitersMask";
15
- ListFormat[ListFormat["AllowTrailingComma"] = 64] = "AllowTrailingComma";
16
- // Whitespace
17
- ListFormat[ListFormat["Indented"] = 128] = "Indented";
18
- ListFormat[ListFormat["SpaceBetweenBraces"] = 256] = "SpaceBetweenBraces";
19
- ListFormat[ListFormat["SpaceBetweenSiblings"] = 512] = "SpaceBetweenSiblings";
20
- // Brackets/Braces
21
- ListFormat[ListFormat["Braces"] = 1024] = "Braces";
22
- ListFormat[ListFormat["Parenthesis"] = 2048] = "Parenthesis";
23
- ListFormat[ListFormat["AngleBrackets"] = 4096] = "AngleBrackets";
24
- ListFormat[ListFormat["SquareBrackets"] = 8192] = "SquareBrackets";
25
- ListFormat[ListFormat["BracketsMask"] = 15360] = "BracketsMask";
26
- ListFormat[ListFormat["OptionalIfUndefined"] = 16384] = "OptionalIfUndefined";
27
- ListFormat[ListFormat["OptionalIfEmpty"] = 32768] = "OptionalIfEmpty";
28
- ListFormat[ListFormat["Optional"] = 49152] = "Optional";
29
- // Other
30
- ListFormat[ListFormat["PreferNewLine"] = 65536] = "PreferNewLine";
31
- ListFormat[ListFormat["NoTrailingNewLine"] = 131072] = "NoTrailingNewLine";
32
- ListFormat[ListFormat["NoInterveningComments"] = 262144] = "NoInterveningComments";
33
- ListFormat[ListFormat["NoSpaceIfEmpty"] = 524288] = "NoSpaceIfEmpty";
34
- ListFormat[ListFormat["SingleElement"] = 1048576] = "SingleElement";
35
- ListFormat[ListFormat["SpaceAfterList"] = 2097152] = "SpaceAfterList";
36
- // Precomputed Formats
37
- ListFormat[ListFormat["Modifiers"] = 262656] = "Modifiers";
38
- ListFormat[ListFormat["SingleLineTypeLiteralMembers"] = 768] = "SingleLineTypeLiteralMembers";
39
- ListFormat[ListFormat["MultiLineTypeLiteralMembers"] = 32897] = "MultiLineTypeLiteralMembers";
40
- ListFormat[ListFormat["TupleTypeElements"] = 528] = "TupleTypeElements";
41
- ListFormat[ListFormat["UnionTypeConstituents"] = 516] = "UnionTypeConstituents";
42
- ListFormat[ListFormat["IntersectionTypeConstituents"] = 520] = "IntersectionTypeConstituents";
43
- ListFormat[ListFormat["ObjectBindingPatternElements"] = 525136] = "ObjectBindingPatternElements";
44
- ListFormat[ListFormat["ArrayBindingPatternElements"] = 524880] = "ArrayBindingPatternElements";
45
- ListFormat[ListFormat["ObjectLiteralExpressionProperties"] = 526226] = "ObjectLiteralExpressionProperties";
46
- ListFormat[ListFormat["ArrayLiteralExpressionElements"] = 8914] = "ArrayLiteralExpressionElements";
47
- ListFormat[ListFormat["CommaListElements"] = 528] = "CommaListElements";
48
- ListFormat[ListFormat["CallExpressionArguments"] = 2576] = "CallExpressionArguments";
49
- ListFormat[ListFormat["TemplateExpressionSpans"] = 262144] = "TemplateExpressionSpans";
50
- ListFormat[ListFormat["SingleLineBlockStatements"] = 768] = "SingleLineBlockStatements";
51
- ListFormat[ListFormat["MultiLineBlockStatements"] = 129] = "MultiLineBlockStatements";
52
- ListFormat[ListFormat["VariableDeclarationList"] = 528] = "VariableDeclarationList";
53
- ListFormat[ListFormat["SingleLineFunctionBodyStatements"] = 768] = "SingleLineFunctionBodyStatements";
54
- ListFormat[ListFormat["MultiLineFunctionBodyStatements"] = 1] = "MultiLineFunctionBodyStatements";
55
- ListFormat[ListFormat["CaseBlockClauses"] = 129] = "CaseBlockClauses";
56
- ListFormat[ListFormat["NamedImportsOrExportsElements"] = 525136] = "NamedImportsOrExportsElements";
57
- ListFormat[ListFormat["JsxElementOrFragmentChildren"] = 262144] = "JsxElementOrFragmentChildren";
58
- ListFormat[ListFormat["JsxElementAttributes"] = 262656] = "JsxElementAttributes";
59
- ListFormat[ListFormat["CaseOrDefaultClauseStatements"] = 163969] = "CaseOrDefaultClauseStatements";
60
- ListFormat[ListFormat["SourceFileStatements"] = 131073] = "SourceFileStatements";
61
- ListFormat[ListFormat["TypeArguments"] = 53776] = "TypeArguments";
62
- ListFormat[ListFormat["TypeParameters"] = 53776] = "TypeParameters";
63
- ListFormat[ListFormat["Parameters"] = 2576] = "Parameters";
64
- ListFormat[ListFormat["IndexSignatureParameters"] = 8848] = "IndexSignatureParameters";
65
- })(ListFormat || (ListFormat = {}));
package/dist/utilities.js DELETED
@@ -1,427 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/compiler/utilities.ts e src/compiler/transformer.ts: o namespace virou
2
- // módulo ES, com os imports explícitos. Os writers do printer — o de texto, o de uma linha só e o que adia o ponto e
3
- // vírgula final —, a escrita dos comentários e a notificação que não faz nada.
4
- import { CharacterCodes, NewLineKind, computeLineAndCharacterOfPosition, computeLineStarts, filter, getIndentSize, getIndentString, getLeadingCommentRanges, getLineOfLocalPositionFromLineMap, isPinnedComment, isWhiteSpaceLike, isWhiteSpaceSingleLine, last, noop, skipTrivia, } from "./_namespaces/ts.js";
5
- const stringWriter = createSingleLineStringWriter();
6
- function createSingleLineStringWriter() {
7
- let str = "";
8
- const writeText = text => str += text;
9
- return {
10
- getText: () => str,
11
- write: writeText,
12
- rawWrite: writeText,
13
- writeKeyword: writeText,
14
- writeOperator: writeText,
15
- writePunctuation: writeText,
16
- writeSpace: writeText,
17
- writeStringLiteral: writeText,
18
- writeLiteral: writeText,
19
- writeParameter: writeText,
20
- writeProperty: writeText,
21
- writeSymbol: (s, _) => writeText(s),
22
- writeTrailingSemicolon: writeText,
23
- writeComment: writeText,
24
- getTextPos: () => str.length,
25
- getLine: () => 0,
26
- getColumn: () => 0,
27
- getIndent: () => 0,
28
- isAtStartOfLine: () => false,
29
- hasTrailingComment: () => false,
30
- hasTrailingWhitespace: () => !!str.length && isWhiteSpaceLike(str.charCodeAt(str.length - 1)),
31
- // Completely ignore indentation for string writers. And map newlines to
32
- // a single space.
33
- writeLine: () => str += " ",
34
- increaseIndent: noop,
35
- decreaseIndent: noop,
36
- clear: () => str = "",
37
- trackSymbol: noop,
38
- reportInaccessibleThisError: noop,
39
- reportInaccessibleUniqueSymbolError: noop,
40
- };
41
- }
42
- export function usingSingleLineStringWriter(action) {
43
- const oldString = stringWriter.getText();
44
- try {
45
- action(stringWriter);
46
- return stringWriter.getText();
47
- }
48
- finally {
49
- stringWriter.clear();
50
- stringWriter.writeKeyword(oldString);
51
- }
52
- }
53
- /**
54
- * Returns a value indicating whether a name is unique globally or within the current file.
55
- * Note: This does not consider whether a name appears as a free identifier or not, so at the expression `x.y` this includes both `x` and `y`.
56
- */
57
- export function isFileLevelUniqueName(sourceFile, name, hasGlobalName) {
58
- return !(hasGlobalName && hasGlobalName(name)) && !sourceFile.identifiers.has(name);
59
- }
60
- export function createTextWriter(newLine) {
61
- let output;
62
- let indent;
63
- let lineStart;
64
- let lineCount;
65
- let linePos;
66
- let hasTrailingComment = false;
67
- function updateLineCountAndPosFor(s) {
68
- const lineStartsOfS = computeLineStarts(s);
69
- if (lineStartsOfS.length > 1) {
70
- lineCount = lineCount + lineStartsOfS.length - 1;
71
- linePos = output.length - s.length + last(lineStartsOfS);
72
- lineStart = (linePos - output.length) === 0;
73
- }
74
- else {
75
- lineStart = false;
76
- }
77
- }
78
- function writeText(s) {
79
- if (s && s.length) {
80
- if (lineStart) {
81
- s = getIndentString(indent) + s;
82
- lineStart = false;
83
- }
84
- output += s;
85
- updateLineCountAndPosFor(s);
86
- }
87
- }
88
- function write(s) {
89
- if (s)
90
- hasTrailingComment = false;
91
- writeText(s);
92
- }
93
- function writeComment(s) {
94
- if (s)
95
- hasTrailingComment = true;
96
- writeText(s);
97
- }
98
- function reset() {
99
- output = "";
100
- indent = 0;
101
- lineStart = true;
102
- lineCount = 0;
103
- linePos = 0;
104
- hasTrailingComment = false;
105
- }
106
- function rawWrite(s) {
107
- if (s !== undefined) {
108
- output += s;
109
- updateLineCountAndPosFor(s);
110
- hasTrailingComment = false;
111
- }
112
- }
113
- function writeLiteral(s) {
114
- if (s && s.length) {
115
- write(s);
116
- }
117
- }
118
- function writeLine(force) {
119
- if (!lineStart || force) {
120
- output += newLine;
121
- lineCount++;
122
- linePos = output.length;
123
- lineStart = true;
124
- hasTrailingComment = false;
125
- }
126
- }
127
- function getTextPosWithWriteLine() {
128
- return lineStart ? output.length : (output.length + newLine.length);
129
- }
130
- reset();
131
- return {
132
- write,
133
- rawWrite,
134
- writeLiteral,
135
- writeLine,
136
- increaseIndent: () => { indent++; },
137
- decreaseIndent: () => { indent--; },
138
- getIndent: () => indent,
139
- getTextPos: () => output.length,
140
- getLine: () => lineCount,
141
- getColumn: () => lineStart ? indent * getIndentSize() : output.length - linePos,
142
- getText: () => output,
143
- isAtStartOfLine: () => lineStart,
144
- hasTrailingComment: () => hasTrailingComment,
145
- hasTrailingWhitespace: () => !!output.length && isWhiteSpaceLike(output.charCodeAt(output.length - 1)),
146
- clear: reset,
147
- reportInaccessibleThisError: noop,
148
- reportInaccessibleUniqueSymbolError: noop,
149
- trackSymbol: noop,
150
- writeKeyword: write,
151
- writeOperator: write,
152
- writeParameter: write,
153
- writeProperty: write,
154
- writePunctuation: write,
155
- writeSpace: write,
156
- writeStringLiteral: write,
157
- writeSymbol: (s, _) => write(s),
158
- writeTrailingSemicolon: write,
159
- writeComment,
160
- getTextPosWithWriteLine
161
- };
162
- }
163
- export function getTrailingSemicolonDeferringWriter(writer) {
164
- let pendingTrailingSemicolon = false;
165
- function commitPendingTrailingSemicolon() {
166
- if (pendingTrailingSemicolon) {
167
- writer.writeTrailingSemicolon(";");
168
- pendingTrailingSemicolon = false;
169
- }
170
- }
171
- return {
172
- ...writer,
173
- writeTrailingSemicolon() {
174
- pendingTrailingSemicolon = true;
175
- },
176
- writeLiteral(s) {
177
- commitPendingTrailingSemicolon();
178
- writer.writeLiteral(s);
179
- },
180
- writeStringLiteral(s) {
181
- commitPendingTrailingSemicolon();
182
- writer.writeStringLiteral(s);
183
- },
184
- writeSymbol(s, sym) {
185
- commitPendingTrailingSemicolon();
186
- writer.writeSymbol(s, sym);
187
- },
188
- writePunctuation(s) {
189
- commitPendingTrailingSemicolon();
190
- writer.writePunctuation(s);
191
- },
192
- writeKeyword(s) {
193
- commitPendingTrailingSemicolon();
194
- writer.writeKeyword(s);
195
- },
196
- writeOperator(s) {
197
- commitPendingTrailingSemicolon();
198
- writer.writeOperator(s);
199
- },
200
- writeParameter(s) {
201
- commitPendingTrailingSemicolon();
202
- writer.writeParameter(s);
203
- },
204
- writeSpace(s) {
205
- commitPendingTrailingSemicolon();
206
- writer.writeSpace(s);
207
- },
208
- writeProperty(s) {
209
- commitPendingTrailingSemicolon();
210
- writer.writeProperty(s);
211
- },
212
- writeComment(s) {
213
- commitPendingTrailingSemicolon();
214
- writer.writeComment(s);
215
- },
216
- writeLine() {
217
- commitPendingTrailingSemicolon();
218
- writer.writeLine();
219
- },
220
- increaseIndent() {
221
- commitPendingTrailingSemicolon();
222
- writer.increaseIndent();
223
- },
224
- decreaseIndent() {
225
- commitPendingTrailingSemicolon();
226
- writer.decreaseIndent();
227
- },
228
- };
229
- }
230
- export function emitNewLineBeforeLeadingComments(lineMap, writer, node, leadingComments) {
231
- emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, node.pos, leadingComments);
232
- }
233
- export function emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, pos, leadingComments) {
234
- // If the leading comments start on different line than the start of node, write new line
235
- if (leadingComments && leadingComments.length && pos !== leadingComments[0].pos &&
236
- getLineOfLocalPositionFromLineMap(lineMap, pos) !== getLineOfLocalPositionFromLineMap(lineMap, leadingComments[0].pos)) {
237
- writer.writeLine();
238
- }
239
- }
240
- export function emitNewLineBeforeLeadingCommentOfPosition(lineMap, writer, pos, commentPos) {
241
- // If the leading comments start on different line than the start of node, write new line
242
- if (pos !== commentPos &&
243
- getLineOfLocalPositionFromLineMap(lineMap, pos) !== getLineOfLocalPositionFromLineMap(lineMap, commentPos)) {
244
- writer.writeLine();
245
- }
246
- }
247
- export function emitComments(text, lineMap, writer, comments, leadingSeparator, trailingSeparator, newLine, writeComment) {
248
- if (comments && comments.length > 0) {
249
- if (leadingSeparator) {
250
- writer.writeSpace(" ");
251
- }
252
- let emitInterveningSeparator = false;
253
- for (const comment of comments) {
254
- if (emitInterveningSeparator) {
255
- writer.writeSpace(" ");
256
- emitInterveningSeparator = false;
257
- }
258
- writeComment(text, lineMap, writer, comment.pos, comment.end, newLine);
259
- if (comment.hasTrailingNewLine) {
260
- writer.writeLine();
261
- }
262
- else {
263
- emitInterveningSeparator = true;
264
- }
265
- }
266
- if (emitInterveningSeparator && trailingSeparator) {
267
- writer.writeSpace(" ");
268
- }
269
- }
270
- }
271
- /**
272
- * Detached comment is a comment at the top of file or function body that is separated from
273
- * the next statement by space.
274
- */
275
- export function emitDetachedComments(text, lineMap, writer, writeComment, node, newLine, removeComments) {
276
- let leadingComments;
277
- let currentDetachedCommentInfo;
278
- if (removeComments) {
279
- // removeComments is true, only reserve pinned comment at the top of file
280
- // For example:
281
- // /*! Pinned Comment */
282
- //
283
- // var x = 10;
284
- if (node.pos === 0) {
285
- leadingComments = filter(getLeadingCommentRanges(text, node.pos), isPinnedCommentLocal);
286
- }
287
- }
288
- else {
289
- // removeComments is false, just get detached as normal and bypass the process to filter comment
290
- leadingComments = getLeadingCommentRanges(text, node.pos);
291
- }
292
- if (leadingComments) {
293
- const detachedComments = [];
294
- let lastComment;
295
- for (const comment of leadingComments) {
296
- if (lastComment) {
297
- const lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, lastComment.end);
298
- const commentLine = getLineOfLocalPositionFromLineMap(lineMap, comment.pos);
299
- if (commentLine >= lastCommentLine + 2) {
300
- // There was a blank line between the last comment and this comment. This
301
- // comment is not part of the copyright comments. Return what we have so
302
- // far.
303
- break;
304
- }
305
- }
306
- detachedComments.push(comment);
307
- lastComment = comment;
308
- }
309
- if (detachedComments.length) {
310
- // All comments look like they could have been part of the copyright header. Make
311
- // sure there is at least one blank line between it and the node. If not, it's not
312
- // a copyright header.
313
- const lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, last(detachedComments).end);
314
- const nodeLine = getLineOfLocalPositionFromLineMap(lineMap, skipTrivia(text, node.pos));
315
- if (nodeLine >= lastCommentLine + 2) {
316
- // Valid detachedComments
317
- emitNewLineBeforeLeadingComments(lineMap, writer, node, leadingComments);
318
- emitComments(text, lineMap, writer, detachedComments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeComment);
319
- currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: last(detachedComments).end };
320
- }
321
- }
322
- }
323
- return currentDetachedCommentInfo;
324
- function isPinnedCommentLocal(comment) {
325
- return isPinnedComment(text, comment.pos);
326
- }
327
- }
328
- export function writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine) {
329
- if (text.charCodeAt(commentPos + 1) === CharacterCodes.asterisk) {
330
- const firstCommentLineAndCharacter = computeLineAndCharacterOfPosition(lineMap, commentPos);
331
- const lineCount = lineMap.length;
332
- let firstCommentLineIndent;
333
- for (let pos = commentPos, currentLine = firstCommentLineAndCharacter.line; pos < commentEnd; currentLine++) {
334
- const nextLineStart = (currentLine + 1) === lineCount
335
- ? text.length + 1
336
- : lineMap[currentLine + 1];
337
- if (pos !== commentPos) {
338
- // If we are not emitting first line, we need to write the spaces to adjust the alignment
339
- if (firstCommentLineIndent === undefined) {
340
- firstCommentLineIndent = calculateIndent(text, lineMap[firstCommentLineAndCharacter.line], commentPos);
341
- }
342
- // These are number of spaces writer is going to write at current indent
343
- const currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
344
- // Number of spaces we want to be writing
345
- // eg: Assume writer indent
346
- // module m {
347
- // /* starts at character 9 this is line 1
348
- // * starts at character pos 4 line --1 = 8 - 8 + 3
349
- // More left indented comment */ --2 = 8 - 8 + 2
350
- // class c { }
351
- // }
352
- // module m {
353
- // /* this is line 1 -- Assume current writer indent 8
354
- // * line --3 = 8 - 4 + 5
355
- // More right indented comment */ --4 = 8 - 4 + 11
356
- // class c { }
357
- // }
358
- const spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(text, pos, nextLineStart);
359
- if (spacesToEmit > 0) {
360
- let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
361
- const indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
362
- // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces
363
- writer.rawWrite(indentSizeSpaceString);
364
- // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces)
365
- while (numberOfSingleSpacesToEmit) {
366
- writer.rawWrite(" ");
367
- numberOfSingleSpacesToEmit--;
368
- }
369
- }
370
- else {
371
- // No spaces to emit write empty string
372
- writer.rawWrite("");
373
- }
374
- }
375
- // Write the comment line text
376
- writeTrimmedCurrentLine(text, commentEnd, writer, newLine, pos, nextLineStart);
377
- pos = nextLineStart;
378
- }
379
- }
380
- else {
381
- // Single line comment of style //....
382
- writer.writeComment(text.substring(commentPos, commentEnd));
383
- }
384
- }
385
- function writeTrimmedCurrentLine(text, commentEnd, writer, newLine, pos, nextLineStart) {
386
- const end = Math.min(commentEnd, nextLineStart - 1);
387
- const currentLineText = text.substring(pos, end).replace(/^\s+|\s+$/g, "");
388
- if (currentLineText) {
389
- // trimmed forward and ending spaces text
390
- writer.writeComment(currentLineText);
391
- if (end !== commentEnd) {
392
- writer.writeLine();
393
- }
394
- }
395
- else {
396
- // Empty string - make sure we write empty line
397
- writer.rawWrite(newLine);
398
- }
399
- }
400
- function calculateIndent(text, pos, end) {
401
- let currentLineIndent = 0;
402
- for (; pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos)); pos++) {
403
- if (text.charCodeAt(pos) === CharacterCodes.tab) {
404
- // Tabs = TabSize = indent size and go to next tabStop
405
- currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
406
- }
407
- else {
408
- // Single space
409
- currentLineIndent++;
410
- }
411
- }
412
- return currentLineIndent;
413
- }
414
- const carriageReturnLineFeed = "\r\n";
415
- const lineFeed = "\n";
416
- export function getNewLineCharacter(options, getNewLine) {
417
- switch (options.newLine) {
418
- case NewLineKind.CarriageReturnLineFeed:
419
- return carriageReturnLineFeed;
420
- case NewLineKind.LineFeed:
421
- return lineFeed;
422
- }
423
- return getNewLine ? getNewLine() : carriageReturnLineFeed;
424
- }
425
- export function noEmitNotification(hint, node, callback) {
426
- callback(hint, node);
427
- }