espolar 0.1.0 → 0.1.2
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.d.ts +292 -5
- package/dist/index.js +32 -20
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -70,18 +70,29 @@ interface PrintOptions<Data> {
|
|
|
70
70
|
printers?: Printers<Data>;
|
|
71
71
|
getLeadingComments?: (node: AST.Node) => Comment[] | undefined;
|
|
72
72
|
getTrailingComments?: (node: AST.Node) => Comment[] | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Provide additional source range for the left parenthesis of `CallExpression` and `NewExpression`.
|
|
75
|
+
* This is useful for language tools that want to provide signature hints when user enter `(`.
|
|
76
|
+
*
|
|
77
|
+
* @notes This hook will not interact with parentheses around the callee.
|
|
78
|
+
*
|
|
79
|
+
* @param node The `CallExpression` or `NewExpression` node.
|
|
80
|
+
* @returns The source range of the left parenthesis, `undefined` if not available.
|
|
81
|
+
*/
|
|
82
|
+
experimentalGetLeftParenSourceRange?: (node: AST.CallExpression | AST.NewExpression) => SourceRange | undefined;
|
|
73
83
|
}
|
|
74
|
-
interface PrinterContext<Data> {
|
|
84
|
+
interface PrinterContext<Data = any> {
|
|
85
|
+
readonly options: PrintOptions<Data>;
|
|
75
86
|
readonly source: string;
|
|
76
87
|
readonly generatedOffset: number;
|
|
77
88
|
write(text: string): void;
|
|
89
|
+
writeMapped(text: string, sourceStart: number, sourceEnd: number, data?: Data): void;
|
|
78
90
|
writeNode(node: AST.Node | null | undefined): void;
|
|
79
91
|
writeNodeList(nodes: readonly (AST.Node | null | undefined)[], separator: string): void;
|
|
80
92
|
writeNodeListWithSourceGaps(nodes: readonly (AST.Node | null | undefined)[], fallbackSeparator: string): void;
|
|
81
|
-
writePreservedNode(node: AST.Node): void;
|
|
82
93
|
writeSource(start: number, end: number, data: Data): void;
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
writePreservedNode(node: AST.Node): void;
|
|
95
|
+
appendMapping(sourceRange: SourceRange, generatedStart: number, generatedEnd: number, data?: Data): void;
|
|
85
96
|
}
|
|
86
97
|
type NodePrinter<Key extends AST_NODE_TYPES, Data> = (node: Extract<AST.Node, {
|
|
87
98
|
type: Key;
|
|
@@ -96,4 +107,280 @@ declare function defaultIsUntouched(node: AST.Node): boolean | SourceRange;
|
|
|
96
107
|
declare function defaultGetMappingData(node?: AST.Node | null): unknown;
|
|
97
108
|
declare function defaultCombineMappingData(left: unknown, right: unknown): unknown;
|
|
98
109
|
//#endregion
|
|
99
|
-
|
|
110
|
+
//#region src/printers.d.ts
|
|
111
|
+
declare const defaultPrinters: {
|
|
112
|
+
Program: typeof printProgram;
|
|
113
|
+
Identifier: typeof printIdentifier;
|
|
114
|
+
PrivateIdentifier: typeof printPrivateIdentifier;
|
|
115
|
+
Literal: typeof printLiteral;
|
|
116
|
+
ExpressionStatement: typeof printExpressionStatement;
|
|
117
|
+
EmptyStatement: typeof printEmptyStatement;
|
|
118
|
+
VariableDeclaration: typeof printVariableDeclaration;
|
|
119
|
+
VariableDeclarator: typeof printVariableDeclarator;
|
|
120
|
+
BlockStatement: typeof printBlockStatement;
|
|
121
|
+
ReturnStatement: typeof printReturnStatement;
|
|
122
|
+
ThrowStatement: typeof printThrowStatement;
|
|
123
|
+
DebuggerStatement: typeof printDebuggerStatement;
|
|
124
|
+
BreakStatement: typeof printBreakStatement;
|
|
125
|
+
ContinueStatement: typeof printContinueStatement;
|
|
126
|
+
LabeledStatement: typeof printLabeledStatement;
|
|
127
|
+
WhileStatement: typeof printWhileStatement;
|
|
128
|
+
DoWhileStatement: typeof printDoWhileStatement;
|
|
129
|
+
IfStatement: typeof printIfStatement;
|
|
130
|
+
ForStatement: typeof printForStatement;
|
|
131
|
+
ForInStatement: typeof printForInStatement;
|
|
132
|
+
ForOfStatement: typeof printForOfStatement;
|
|
133
|
+
SwitchStatement: typeof printSwitchStatement;
|
|
134
|
+
SwitchCase: typeof printSwitchCase;
|
|
135
|
+
TryStatement: typeof printTryStatement;
|
|
136
|
+
WithStatement: typeof printWithStatement;
|
|
137
|
+
FunctionDeclaration: typeof printFunctionDeclaration;
|
|
138
|
+
FunctionExpression: typeof printFunctionExpression;
|
|
139
|
+
ArrowFunctionExpression: typeof printArrowFunctionExpression;
|
|
140
|
+
UnaryExpression: typeof printUnaryExpression;
|
|
141
|
+
UpdateExpression: typeof printUpdateExpression;
|
|
142
|
+
BinaryExpression: typeof printBinaryExpression;
|
|
143
|
+
LogicalExpression: typeof printBinaryExpression;
|
|
144
|
+
AssignmentExpression: typeof printBinaryExpression;
|
|
145
|
+
ConditionalExpression: typeof printConditionalExpression;
|
|
146
|
+
YieldExpression: typeof printYieldExpression;
|
|
147
|
+
AwaitExpression: typeof printAwaitExpression;
|
|
148
|
+
SequenceExpression: typeof printSequenceExpression;
|
|
149
|
+
CallExpression: typeof printCallExpression;
|
|
150
|
+
NewExpression: typeof printNewExpression;
|
|
151
|
+
ChainExpression: typeof printChainExpression;
|
|
152
|
+
MemberExpression: typeof printMemberExpression;
|
|
153
|
+
ObjectExpression: typeof printObjectExpression;
|
|
154
|
+
ObjectPattern: typeof printObjectPattern;
|
|
155
|
+
ArrayExpression: typeof printArrayExpression;
|
|
156
|
+
ArrayPattern: typeof printArrayPattern;
|
|
157
|
+
Property: typeof printProperty;
|
|
158
|
+
SpreadElement: typeof printSpreadElement;
|
|
159
|
+
RestElement: typeof printRestElement;
|
|
160
|
+
AssignmentPattern: typeof printAssignmentPattern;
|
|
161
|
+
TemplateLiteral: typeof printTemplateLiteral;
|
|
162
|
+
TaggedTemplateExpression: typeof printTaggedTemplateExpression;
|
|
163
|
+
ThisExpression: typeof printThisExpression;
|
|
164
|
+
Super: typeof printSuper;
|
|
165
|
+
MetaProperty: typeof printMetaProperty;
|
|
166
|
+
ParenthesizedExpression: typeof printParenthesizedExpression;
|
|
167
|
+
ClassDeclaration: typeof printClassDeclaration;
|
|
168
|
+
ClassExpression: typeof printClassExpression;
|
|
169
|
+
ClassBody: typeof printClassBody;
|
|
170
|
+
StaticBlock: typeof printStaticBlock;
|
|
171
|
+
PropertyDefinition: typeof printPropertyDefinition;
|
|
172
|
+
AccessorProperty: typeof printPropertyDefinition;
|
|
173
|
+
MethodDefinition: typeof printMethodDefinition;
|
|
174
|
+
Decorator: typeof printDecorator;
|
|
175
|
+
ImportDeclaration: typeof printImportDeclaration;
|
|
176
|
+
ImportExpression: typeof printImportExpression;
|
|
177
|
+
ImportSpecifier: typeof printImportSpecifier;
|
|
178
|
+
ExportNamedDeclaration: typeof printExportNamedDeclaration;
|
|
179
|
+
ExportDefaultDeclaration: typeof printExportDefaultDeclaration;
|
|
180
|
+
ExportAllDeclaration: typeof printExportAllDeclaration;
|
|
181
|
+
ExportSpecifier: typeof printExportSpecifier;
|
|
182
|
+
TSAsExpression: typeof printTSAsExpression;
|
|
183
|
+
TSSatisfiesExpression: typeof printTSSatisfiesExpression;
|
|
184
|
+
TSTypeAssertion: typeof printTSTypeAssertion;
|
|
185
|
+
TSNonNullExpression: typeof printTSNonNullExpression;
|
|
186
|
+
TSTypeAnnotation: typeof printTSTypeAnnotation;
|
|
187
|
+
TSTypeAliasDeclaration: typeof printTSTypeAliasDeclaration;
|
|
188
|
+
TSInterfaceDeclaration: typeof printTSInterfaceDeclaration;
|
|
189
|
+
TSExpressionWithTypeArguments: typeof printTSExpressionWithTypeArguments;
|
|
190
|
+
TSClassImplements: typeof printTSExpressionWithTypeArguments;
|
|
191
|
+
TSInterfaceHeritage: typeof printTSExpressionWithTypeArguments;
|
|
192
|
+
TSFunctionType: typeof printTSFunctionType;
|
|
193
|
+
TSConstructorType: typeof printTSConstructorType;
|
|
194
|
+
TSMethodSignature: typeof printTSMethodSignature;
|
|
195
|
+
TSCallSignatureDeclaration: typeof printTSCallSignatureDeclaration;
|
|
196
|
+
TSConstructSignatureDeclaration: typeof printTSConstructSignatureDeclaration;
|
|
197
|
+
TSIndexSignature: typeof printTSIndexSignature;
|
|
198
|
+
TSPropertySignature: typeof printTSPropertySignature;
|
|
199
|
+
TSTypeParameterDeclaration: typeof printTypeParameterDeclaration;
|
|
200
|
+
TSTypeParameterInstantiation: typeof printTypeParameterInstantiation;
|
|
201
|
+
TSTypeParameter: typeof printTSTypeParameter;
|
|
202
|
+
TSTypeReference: typeof printTSTypeReference;
|
|
203
|
+
TSQualifiedName: typeof printTSQualifiedName;
|
|
204
|
+
TSUnionType: typeof printJoinedTypes;
|
|
205
|
+
TSIntersectionType: typeof printJoinedTypes;
|
|
206
|
+
TSArrayType: typeof printTSArrayType;
|
|
207
|
+
TSTupleType: typeof printTSTupleType;
|
|
208
|
+
TSNamedTupleMember: typeof printTSNamedTupleMember;
|
|
209
|
+
TSTypeLiteral: typeof printTSTypeLiteral;
|
|
210
|
+
TSTypeOperator: typeof printTSTypeOperator;
|
|
211
|
+
TSTypePredicate: typeof printTSTypePredicate;
|
|
212
|
+
TSTypeQuery: typeof printTSTypeQuery;
|
|
213
|
+
TSMappedType: typeof printTSMappedType;
|
|
214
|
+
TSConditionalType: typeof printTSConditionalType;
|
|
215
|
+
TSInferType: typeof printTSInferType;
|
|
216
|
+
TSIndexedAccessType: typeof printTSIndexedAccessType;
|
|
217
|
+
TSOptionalType: typeof printTSOptionalType;
|
|
218
|
+
TSRestType: typeof printTSRestType;
|
|
219
|
+
TSThisType: typeof printTSThisType;
|
|
220
|
+
TSLiteralType: typeof printTSLiteralType;
|
|
221
|
+
TSTemplateLiteralType: typeof printTSTemplateLiteralType;
|
|
222
|
+
TSImportType: typeof printTSImportType;
|
|
223
|
+
TSImportEqualsDeclaration: typeof printTSImportEqualsDeclaration;
|
|
224
|
+
TSExternalModuleReference: typeof printTSExternalModuleReference;
|
|
225
|
+
TSEnumDeclaration: typeof printTSEnumDeclaration;
|
|
226
|
+
TSEnumMember: typeof printTSEnumMember;
|
|
227
|
+
TSModuleDeclaration: typeof printTSModuleDeclaration;
|
|
228
|
+
TSModuleBlock: typeof printTSModuleBlock;
|
|
229
|
+
TSDeclareFunction: typeof printTSDeclareFunction;
|
|
230
|
+
TSParameterProperty: typeof printTSParameterProperty;
|
|
231
|
+
TSAbstractMethodDefinition: typeof printMethodDefinition;
|
|
232
|
+
TSAbstractPropertyDefinition: typeof printPropertyDefinition;
|
|
233
|
+
TSAbstractAccessorProperty: typeof printPropertyDefinition;
|
|
234
|
+
TSExportAssignment: typeof printTSExportAssignment;
|
|
235
|
+
TSNamespaceExportDeclaration: typeof printTSNamespaceExportDeclaration;
|
|
236
|
+
TSInstantiationExpression: typeof printTSInstantiationExpression;
|
|
237
|
+
TSParenthesizedType: typeof printTSParenthesizedType;
|
|
238
|
+
TSInterfaceBody: typeof printTSInterfaceBody;
|
|
239
|
+
TSStringKeyword: typeof printKeywordType;
|
|
240
|
+
TSNumberKeyword: typeof printKeywordType;
|
|
241
|
+
TSBooleanKeyword: typeof printKeywordType;
|
|
242
|
+
TSVoidKeyword: typeof printKeywordType;
|
|
243
|
+
TSUnknownKeyword: typeof printKeywordType;
|
|
244
|
+
TSAnyKeyword: typeof printKeywordType;
|
|
245
|
+
TSNeverKeyword: typeof printKeywordType;
|
|
246
|
+
TSNullKeyword: typeof printKeywordType;
|
|
247
|
+
TSUndefinedKeyword: typeof printKeywordType;
|
|
248
|
+
TSObjectKeyword: typeof printKeywordType;
|
|
249
|
+
TSSymbolKeyword: typeof printKeywordType;
|
|
250
|
+
TSBigIntKeyword: typeof printKeywordType;
|
|
251
|
+
TSIntrinsicKeyword: typeof printKeywordType;
|
|
252
|
+
};
|
|
253
|
+
declare function printProgram(program: AST.Program, context: PrinterContext): void;
|
|
254
|
+
declare function printExpressionStatement(statement: AST.ExpressionStatement, context: PrinterContext): void;
|
|
255
|
+
declare function printEmptyStatement(_statement: AST.EmptyStatement, context: PrinterContext): void;
|
|
256
|
+
declare function printVariableDeclaration(declaration: AST.VariableDeclaration, context: PrinterContext): void;
|
|
257
|
+
declare function printVariableDeclarator(declarator: AST.VariableDeclarator, context: PrinterContext): void;
|
|
258
|
+
declare function printBlockStatement(block: AST.BlockStatement, context: PrinterContext): void;
|
|
259
|
+
declare function printReturnStatement(statement: AST.ReturnStatement, context: PrinterContext): void;
|
|
260
|
+
declare function printThrowStatement(statement: AST.ThrowStatement, context: PrinterContext): void;
|
|
261
|
+
declare function printDebuggerStatement(_statement: AST.DebuggerStatement, context: PrinterContext): void;
|
|
262
|
+
declare function printBreakStatement(statement: AST.BreakStatement, context: PrinterContext): void;
|
|
263
|
+
declare function printContinueStatement(statement: AST.ContinueStatement, context: PrinterContext): void;
|
|
264
|
+
declare function printLabeledStatement(statement: AST.LabeledStatement, context: PrinterContext): void;
|
|
265
|
+
declare function printWhileStatement(statement: AST.WhileStatement, context: PrinterContext): void;
|
|
266
|
+
declare function printDoWhileStatement(statement: AST.DoWhileStatement, context: PrinterContext): void;
|
|
267
|
+
declare function printIfStatement(statement: AST.IfStatement, context: PrinterContext): void;
|
|
268
|
+
declare function printForStatement(statement: AST.ForStatement, context: PrinterContext): void;
|
|
269
|
+
declare function printForInStatement(statement: AST.ForInStatement, context: PrinterContext): void;
|
|
270
|
+
declare function printForOfStatement(statement: AST.ForOfStatement, context: PrinterContext): void;
|
|
271
|
+
declare function printSwitchStatement(statement: AST.SwitchStatement, context: PrinterContext): void;
|
|
272
|
+
declare function printSwitchCase(case_: AST.SwitchCase, context: PrinterContext): void;
|
|
273
|
+
declare function printTryStatement(statement: AST.TryStatement, context: PrinterContext): void;
|
|
274
|
+
declare function printWithStatement(statement: AST.WithStatement, context: PrinterContext): void;
|
|
275
|
+
declare function printIdentifier(identifier: AST.Identifier, context: PrinterContext): void;
|
|
276
|
+
declare function printPrivateIdentifier(identifier: AST.PrivateIdentifier, context: PrinterContext): void;
|
|
277
|
+
declare function printLiteral(literal: AST.Literal, context: PrinterContext): void;
|
|
278
|
+
declare function printUnaryExpression(expr: AST.UnaryExpression, context: PrinterContext): void;
|
|
279
|
+
declare function printUpdateExpression(expr: AST.UpdateExpression, context: PrinterContext): void;
|
|
280
|
+
declare function printBinaryExpression(expression: AST.AssignmentExpression | AST.LogicalExpression | AST.BinaryExpression, context: PrinterContext): void;
|
|
281
|
+
declare function printConditionalExpression(expr: AST.ConditionalExpression, context: PrinterContext): void;
|
|
282
|
+
declare function printYieldExpression(expr: AST.YieldExpression, context: PrinterContext): void;
|
|
283
|
+
declare function printAwaitExpression(expr: AST.AwaitExpression, context: PrinterContext): void;
|
|
284
|
+
declare function printSequenceExpression(expr: AST.SequenceExpression, context: PrinterContext): void;
|
|
285
|
+
declare function printCallExpression(expression: AST.CallExpression, context: PrinterContext): void;
|
|
286
|
+
declare function printNewExpression(expression: AST.NewExpression, context: PrinterContext): void;
|
|
287
|
+
declare function printChainExpression(expression: AST.ChainExpression, context: PrinterContext): void;
|
|
288
|
+
declare function printMemberExpression(expression: AST.MemberExpression, context: PrinterContext): void;
|
|
289
|
+
declare function printObjectExpression(object: AST.ObjectExpression, context: PrinterContext): void;
|
|
290
|
+
declare function printObjectPattern(pattern: AST.ObjectPattern, context: PrinterContext): void;
|
|
291
|
+
declare function printArrayExpression(array: AST.ArrayExpression, context: PrinterContext): void;
|
|
292
|
+
declare function printArrayPattern(pattern: AST.ArrayPattern, context: PrinterContext): void;
|
|
293
|
+
declare function printProperty(property: AST.Property | AST.PropertyDefinition, context: PrinterContext): void;
|
|
294
|
+
declare function printSpreadElement(spread: AST.SpreadElement, context: PrinterContext): void;
|
|
295
|
+
declare function printRestElement(rest: AST.RestElement, context: PrinterContext): void;
|
|
296
|
+
declare function printAssignmentPattern(pattern: AST.AssignmentPattern, context: PrinterContext): void;
|
|
297
|
+
declare function printTemplateLiteral(node: AST.TemplateLiteral, context: PrinterContext): void;
|
|
298
|
+
declare function printTaggedTemplateExpression(node: AST.TaggedTemplateExpression, context: PrinterContext): void;
|
|
299
|
+
declare function printThisExpression(_node: AST.ThisExpression, context: PrinterContext): void;
|
|
300
|
+
declare function printSuper(_node: AST.Super, context: PrinterContext): void;
|
|
301
|
+
declare function printMetaProperty(node: AST.MetaProperty, context: PrinterContext): void;
|
|
302
|
+
declare function printParenthesizedExpression(node: {
|
|
303
|
+
expression: AST.Node;
|
|
304
|
+
}, context: PrinterContext): void;
|
|
305
|
+
declare function printFunctionDeclaration(node: AST.FunctionDeclaration, context: PrinterContext): void;
|
|
306
|
+
declare function printFunctionExpression(node: AST.FunctionExpression, context: PrinterContext): void;
|
|
307
|
+
declare function printArrowFunctionExpression(fn: AST.ArrowFunctionExpression, context: PrinterContext): void;
|
|
308
|
+
declare function printClassDeclaration(node: AST.ClassDeclaration, context: PrinterContext): void;
|
|
309
|
+
declare function printClassExpression(node: AST.ClassExpression, context: PrinterContext): void;
|
|
310
|
+
declare function printClassBody(node: AST.ClassBody, context: PrinterContext): void;
|
|
311
|
+
declare function printStaticBlock(node: AST.StaticBlock, context: PrinterContext): void;
|
|
312
|
+
declare function printDecorator(node: AST.Decorator, context: PrinterContext): void;
|
|
313
|
+
declare function printPropertyDefinition(node: AST.PropertyDefinition | AST.AccessorProperty | AST.TSAbstractAccessorProperty | AST.TSAbstractPropertyDefinition, context: PrinterContext): void;
|
|
314
|
+
declare function printMethodDefinition(node: AST.MethodDefinition | AST.TSAbstractMethodDefinition, context: PrinterContext): void;
|
|
315
|
+
declare function printImportDeclaration(node: AST.ImportDeclaration, context: PrinterContext): void;
|
|
316
|
+
declare function printImportExpression(node: AST.ImportExpression, context: PrinterContext): void;
|
|
317
|
+
declare function printImportSpecifier(node: AST.ImportSpecifier, context: PrinterContext): void;
|
|
318
|
+
declare function printExportNamedDeclaration(node: AST.ExportNamedDeclaration, context: PrinterContext): void;
|
|
319
|
+
declare function printExportDefaultDeclaration(node: AST.ExportDefaultDeclaration, context: PrinterContext): void;
|
|
320
|
+
declare function printExportAllDeclaration(node: AST.ExportAllDeclaration, context: PrinterContext): void;
|
|
321
|
+
declare function printExportSpecifier(node: AST.ExportSpecifier, context: PrinterContext): void;
|
|
322
|
+
declare function printTSAsExpression(expression: AST.TSAsExpression, context: PrinterContext): void;
|
|
323
|
+
declare function printTSSatisfiesExpression(expression: AST.TSSatisfiesExpression, context: PrinterContext): void;
|
|
324
|
+
declare function printTSTypeAssertion(expression: AST.TSTypeAssertion, context: PrinterContext): void;
|
|
325
|
+
declare function printTSNonNullExpression(expression: AST.TSNonNullExpression, context: PrinterContext): void;
|
|
326
|
+
declare function printTSTypeAnnotation(annotation: AST.TSTypeAnnotation, context: PrinterContext): void;
|
|
327
|
+
declare function printTSTypeAliasDeclaration(alias: AST.TSTypeAliasDeclaration, context: PrinterContext): void;
|
|
328
|
+
declare function printTSInterfaceDeclaration(node: AST.TSInterfaceDeclaration, context: PrinterContext): void;
|
|
329
|
+
declare function printTSExpressionWithTypeArguments(node: {
|
|
330
|
+
expression: AST.Node;
|
|
331
|
+
typeArguments?: AST.Node;
|
|
332
|
+
typeParameters?: AST.Node;
|
|
333
|
+
}, context: PrinterContext): void;
|
|
334
|
+
declare function printTSInterfaceBody(body: AST.TSInterfaceBody, context: PrinterContext): void;
|
|
335
|
+
declare function printTSPropertySignature(signature: AST.TSPropertySignature, context: PrinterContext): void;
|
|
336
|
+
declare function printTypeParameterDeclaration(declaration: AST.TSTypeParameterDeclaration, context: PrinterContext): void;
|
|
337
|
+
declare function printTypeParameterInstantiation(instantiation: AST.TSTypeParameterInstantiation, context: PrinterContext): void;
|
|
338
|
+
declare function printTSTypeParameter(parameter: AST.TSTypeParameter, context: PrinterContext): void;
|
|
339
|
+
declare function printTSFunctionType(type: AST.TSFunctionType, context: PrinterContext): void;
|
|
340
|
+
declare function printTSConstructorType(type: AST.TSConstructorType, context: PrinterContext): void;
|
|
341
|
+
declare function printTSMethodSignature(signature: AST.TSMethodSignature, context: PrinterContext): void;
|
|
342
|
+
declare function printTSCallSignatureDeclaration(signature: AST.TSCallSignatureDeclaration, context: PrinterContext): void;
|
|
343
|
+
declare function printTSConstructSignatureDeclaration(signature: AST.TSConstructSignatureDeclaration, context: PrinterContext): void;
|
|
344
|
+
declare function printTSIndexSignature(signature: AST.TSIndexSignature, context: PrinterContext): void;
|
|
345
|
+
declare function printTSTypeReference(reference: AST.TSTypeReference, context: PrinterContext): void;
|
|
346
|
+
declare function printTSQualifiedName(name: AST.TSQualifiedName, context: PrinterContext): void;
|
|
347
|
+
declare function printJoinedTypes(joined: AST.TSUnionType | AST.TSIntersectionType, context: PrinterContext): void;
|
|
348
|
+
declare function printTSArrayType(array: AST.TSArrayType, context: PrinterContext): void;
|
|
349
|
+
declare function printTSTupleType(node: AST.TSTupleType, context: PrinterContext): void;
|
|
350
|
+
declare function printTSNamedTupleMember(node: AST.TSNamedTupleMember, context: PrinterContext): void;
|
|
351
|
+
declare function printTSTypeLiteral(literal: AST.TSTypeLiteral, context: PrinterContext): void;
|
|
352
|
+
declare function printTSTypeOperator(node: AST.TSTypeOperator, context: PrinterContext): void;
|
|
353
|
+
declare function printTSTypePredicate(node: AST.TSTypePredicate, context: PrinterContext): void;
|
|
354
|
+
declare function printTSTypeQuery(node: AST.TSTypeQuery, context: PrinterContext): void;
|
|
355
|
+
declare function printTSMappedType(node: AST.TSMappedType, context: PrinterContext): void;
|
|
356
|
+
declare function printTSConditionalType(node: AST.TSConditionalType, context: PrinterContext): void;
|
|
357
|
+
declare function printTSInferType(node: AST.TSInferType, context: PrinterContext): void;
|
|
358
|
+
declare function printTSIndexedAccessType(node: AST.TSIndexedAccessType, context: PrinterContext): void;
|
|
359
|
+
declare function printTSOptionalType(node: AST.TSOptionalType, context: PrinterContext): void;
|
|
360
|
+
declare function printTSRestType(node: AST.TSRestType, context: PrinterContext): void;
|
|
361
|
+
declare function printTSThisType(_node: AST.TSThisType, context: PrinterContext): void;
|
|
362
|
+
declare function printTSLiteralType(literal: AST.TSLiteralType, context: PrinterContext): void;
|
|
363
|
+
declare function printTSTemplateLiteralType(node: AST.TSTemplateLiteralType, context: PrinterContext): void;
|
|
364
|
+
declare function printTSImportType(node: AST.TSImportType, context: PrinterContext): void;
|
|
365
|
+
declare function printTSImportEqualsDeclaration(node: AST.TSImportEqualsDeclaration, context: PrinterContext): void;
|
|
366
|
+
declare function printTSExternalModuleReference(node: AST.TSExternalModuleReference, context: PrinterContext): void;
|
|
367
|
+
declare function printTSEnumDeclaration(node: AST.TSEnumDeclaration, context: PrinterContext): void;
|
|
368
|
+
declare function printTSEnumMember(node: AST.TSEnumMember, context: PrinterContext): void;
|
|
369
|
+
declare function printTSModuleDeclaration(node: AST.TSModuleDeclaration, context: PrinterContext): void;
|
|
370
|
+
declare function printTSModuleBlock(node: AST.TSModuleBlock, context: PrinterContext): void;
|
|
371
|
+
declare function printTSDeclareFunction(node: AST.TSDeclareFunction, context: PrinterContext): void;
|
|
372
|
+
declare function printTSParameterProperty(node: AST.TSParameterProperty, context: PrinterContext): void;
|
|
373
|
+
declare function printTSExportAssignment(node: AST.TSExportAssignment, context: PrinterContext): void;
|
|
374
|
+
declare function printTSNamespaceExportDeclaration(node: AST.TSNamespaceExportDeclaration, context: PrinterContext): void;
|
|
375
|
+
declare function printTSInstantiationExpression(node: {
|
|
376
|
+
expression: AST.Node;
|
|
377
|
+
typeArguments: AST.Node;
|
|
378
|
+
}, context: PrinterContext): void;
|
|
379
|
+
declare function printTSParenthesizedType(node: {
|
|
380
|
+
typeAnnotation: AST.Node;
|
|
381
|
+
}, context: PrinterContext): void;
|
|
382
|
+
declare function printKeywordType(node: Extract<AST.Node, {
|
|
383
|
+
type: `${string}Keyword`;
|
|
384
|
+
}>, context: PrinterContext): void;
|
|
385
|
+
//#endregion
|
|
386
|
+
export { type AST, type Comment, type NodeLike, type NodePrinter, type PrintOptions, type PrintResult, type PrinterContext, type SourceRange, defaultCombineMappingData, defaultGetMappingData, defaultIsUntouched, defaultPrinters, print };
|
package/dist/index.js
CHANGED
|
@@ -282,7 +282,7 @@ function printReturnStatement(statement, context) {
|
|
|
282
282
|
context.write("return");
|
|
283
283
|
if (statement.argument) {
|
|
284
284
|
context.write(" ");
|
|
285
|
-
const needsParensASi = (context.getLeadingComments?.(statement.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
285
|
+
const needsParensASi = (context.options.getLeadingComments?.(statement.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
286
286
|
if (needsParensASi) context.write("(");
|
|
287
287
|
context.writeNode(statement.argument);
|
|
288
288
|
if (needsParensASi) context.write(")");
|
|
@@ -292,7 +292,7 @@ function printReturnStatement(statement, context) {
|
|
|
292
292
|
function printThrowStatement(statement, context) {
|
|
293
293
|
context.write("throw ");
|
|
294
294
|
if (statement.argument) {
|
|
295
|
-
const needsParensASi = (context.getLeadingComments?.(statement.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
295
|
+
const needsParensASi = (context.options.getLeadingComments?.(statement.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
296
296
|
if (needsParensASi) context.write("(");
|
|
297
297
|
context.writeNode(statement.argument);
|
|
298
298
|
if (needsParensASi) context.write(")");
|
|
@@ -454,7 +454,7 @@ function printUpdateExpression(expr, context) {
|
|
|
454
454
|
context.write(expr.operator);
|
|
455
455
|
context.writeNode(expr.argument);
|
|
456
456
|
} else {
|
|
457
|
-
const needsParensASi = (context.getTrailingComments?.(expr.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
457
|
+
const needsParensASi = (context.options.getTrailingComments?.(expr.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
458
458
|
if (needsParensASi) context.write("(");
|
|
459
459
|
context.writeNode(expr.argument);
|
|
460
460
|
if (needsParensASi) context.write(")");
|
|
@@ -493,7 +493,7 @@ function printYieldExpression(expr, context) {
|
|
|
493
493
|
context.write(expr.delegate === true ? "yield*" : "yield");
|
|
494
494
|
if (expr.argument) {
|
|
495
495
|
context.write(" ");
|
|
496
|
-
const needsParensASi = (context.getLeadingComments?.(expr.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
496
|
+
const needsParensASi = (context.options.getLeadingComments?.(expr.argument))?.some((c) => commentNeedsNewline(c)) ?? false;
|
|
497
497
|
if (needsParensASi) context.write("(");
|
|
498
498
|
context.writeNode(expr.argument);
|
|
499
499
|
if (needsParensASi) context.write(")");
|
|
@@ -525,7 +525,10 @@ function printCallExpression(expression, context) {
|
|
|
525
525
|
context.write(")");
|
|
526
526
|
} else context.writeNode(expression.callee);
|
|
527
527
|
if (expression.typeArguments) context.writeNode(expression.typeArguments);
|
|
528
|
-
|
|
528
|
+
if (expression.optional === true) context.write("?.");
|
|
529
|
+
const parenRange = context.options.experimentalGetLeftParenSourceRange?.(expression);
|
|
530
|
+
if (parenRange) context.writeMapped("(", parenRange.start, parenRange.end);
|
|
531
|
+
else context.write("(");
|
|
529
532
|
context.writeNodeList(expression.arguments, ", ");
|
|
530
533
|
context.write(")");
|
|
531
534
|
}
|
|
@@ -537,7 +540,9 @@ function printNewExpression(expression, context) {
|
|
|
537
540
|
context.write(")");
|
|
538
541
|
} else context.writeNode(expression.callee);
|
|
539
542
|
if (expression.typeArguments) context.writeNode(expression.typeArguments);
|
|
540
|
-
context.
|
|
543
|
+
const parenRange = context.options.experimentalGetLeftParenSourceRange?.(expression);
|
|
544
|
+
if (parenRange) context.writeMapped("(", parenRange.start, parenRange.end);
|
|
545
|
+
else context.write("(");
|
|
541
546
|
context.writeNodeList(expression.arguments, ", ");
|
|
542
547
|
context.write(")");
|
|
543
548
|
}
|
|
@@ -896,8 +901,8 @@ function printExportNamedDeclaration(node, context) {
|
|
|
896
901
|
function printExportDefaultDeclaration(node, context) {
|
|
897
902
|
let decl = node.declaration;
|
|
898
903
|
if ("decorators" in decl && decl.decorators && decl.decorators.length > 0) {
|
|
899
|
-
|
|
900
|
-
const
|
|
904
|
+
const { decorators, ...rest } = decl;
|
|
905
|
+
for (const d of decorators) context.writeNode(d);
|
|
901
906
|
decl = rest;
|
|
902
907
|
}
|
|
903
908
|
context.write("export default ");
|
|
@@ -1385,8 +1390,6 @@ function createPrinterContext(options) {
|
|
|
1385
1390
|
...defaultPrinters,
|
|
1386
1391
|
...options.printers
|
|
1387
1392
|
};
|
|
1388
|
-
const getLeadingComments = options.getLeadingComments ?? (() => void 0);
|
|
1389
|
-
const getTrailingComments = options.getTrailingComments ?? (() => void 0);
|
|
1390
1393
|
const appendMapping = (sourceRange, generatedStart, generatedEnd, data) => {
|
|
1391
1394
|
pushMapping(mappings, {
|
|
1392
1395
|
sourceStart: sourceRange.start,
|
|
@@ -1397,6 +1400,7 @@ function createPrinterContext(options) {
|
|
|
1397
1400
|
}, combineMappingData);
|
|
1398
1401
|
};
|
|
1399
1402
|
const context = {
|
|
1403
|
+
options,
|
|
1400
1404
|
source: options.source,
|
|
1401
1405
|
get generatedOffset() {
|
|
1402
1406
|
return generatedOffset;
|
|
@@ -1406,6 +1410,15 @@ function createPrinterContext(options) {
|
|
|
1406
1410
|
chunks.push(text);
|
|
1407
1411
|
generatedOffset += text.length;
|
|
1408
1412
|
},
|
|
1413
|
+
writeMapped(text, sourceStart, sourceEnd, data) {
|
|
1414
|
+
if (text.length === 0 || sourceEnd <= sourceStart) return;
|
|
1415
|
+
const generatedStart = generatedOffset;
|
|
1416
|
+
context.write(text);
|
|
1417
|
+
appendMapping({
|
|
1418
|
+
start: sourceStart,
|
|
1419
|
+
end: sourceEnd
|
|
1420
|
+
}, generatedStart, generatedOffset, data ?? getMappingData(null));
|
|
1421
|
+
},
|
|
1409
1422
|
writeNode(node) {
|
|
1410
1423
|
if (!node) return;
|
|
1411
1424
|
const range = getNodeRange(node);
|
|
@@ -1418,12 +1431,12 @@ function createPrinterContext(options) {
|
|
|
1418
1431
|
}
|
|
1419
1432
|
const printer = printers[node.type];
|
|
1420
1433
|
if (!printer) throw new Error(`No printer registered for node type ${node.type}`);
|
|
1421
|
-
const leadingComments = getLeadingComments(node);
|
|
1434
|
+
const leadingComments = options.getLeadingComments?.(node);
|
|
1422
1435
|
if (leadingComments) for (const c of leadingComments) writeComment(context, c);
|
|
1423
1436
|
const generatedStart = generatedOffset;
|
|
1424
1437
|
printer(node, context);
|
|
1425
1438
|
const generatedEnd = generatedOffset;
|
|
1426
|
-
const trailingComments = getTrailingComments(node);
|
|
1439
|
+
const trailingComments = options.getTrailingComments?.(node);
|
|
1427
1440
|
if (trailingComments) for (const c of trailingComments) writeComment(context, c);
|
|
1428
1441
|
const lastMappingGeneratedEnd = mappings.at(-1)?.generatedEnd ?? 0;
|
|
1429
1442
|
if (range && lastMappingGeneratedEnd <= generatedStart) appendMapping(range, generatedStart, generatedEnd, getMappingData(node));
|
|
@@ -1454,13 +1467,6 @@ function createPrinterContext(options) {
|
|
|
1454
1467
|
else lastRangeEnd = void 0;
|
|
1455
1468
|
}
|
|
1456
1469
|
},
|
|
1457
|
-
writePreservedNode(node) {
|
|
1458
|
-
const range = getNodeRange(node);
|
|
1459
|
-
if (!range) throw new Error(`Cannot preserve node ${node.type} without source offsets`);
|
|
1460
|
-
context.writeSource(range.start, range.end, getMappingData(node));
|
|
1461
|
-
},
|
|
1462
|
-
getLeadingComments,
|
|
1463
|
-
getTrailingComments,
|
|
1464
1470
|
writeSource(start, end, data) {
|
|
1465
1471
|
if (end <= start) return;
|
|
1466
1472
|
const generatedStart = generatedOffset;
|
|
@@ -1470,6 +1476,12 @@ function createPrinterContext(options) {
|
|
|
1470
1476
|
end
|
|
1471
1477
|
}, generatedStart, generatedOffset, data);
|
|
1472
1478
|
},
|
|
1479
|
+
writePreservedNode(node) {
|
|
1480
|
+
const range = getNodeRange(node);
|
|
1481
|
+
if (!range) throw new Error(`Cannot preserve node ${node.type} without source offsets`);
|
|
1482
|
+
context.writeSource(range.start, range.end, getMappingData(node));
|
|
1483
|
+
},
|
|
1484
|
+
appendMapping,
|
|
1473
1485
|
result() {
|
|
1474
1486
|
return {
|
|
1475
1487
|
code: chunks.join(""),
|
|
@@ -1480,4 +1492,4 @@ function createPrinterContext(options) {
|
|
|
1480
1492
|
return context;
|
|
1481
1493
|
}
|
|
1482
1494
|
//#endregion
|
|
1483
|
-
export { defaultCombineMappingData, defaultGetMappingData, defaultIsUntouched, print };
|
|
1495
|
+
export { defaultCombineMappingData, defaultGetMappingData, defaultIsUntouched, defaultPrinters, print };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "espolar",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
5
6
|
"exports": {
|
|
6
7
|
".": {
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
@@ -12,6 +13,10 @@
|
|
|
12
13
|
"files": [
|
|
13
14
|
"dist"
|
|
14
15
|
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"url": "git+https://github.com/piovium/espolar.git"
|
|
19
|
+
},
|
|
15
20
|
"engines": {
|
|
16
21
|
"node": ">= 26.0.0"
|
|
17
22
|
},
|