espolar 0.1.3 → 0.1.4
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/README.md +12 -12
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,18 +92,18 @@ Main entry point. Returns `PrintResult<Data>`.
|
|
|
92
92
|
|
|
93
93
|
The context object passed to each printer function.
|
|
94
94
|
|
|
95
|
-
| Method/Property
|
|
96
|
-
|
|
|
97
|
-
| `readonly source: string`
|
|
98
|
-
| `readonly generatedOffset: number`
|
|
99
|
-
| `write(text: string)`
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `writeSource(start, end, data)`
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
95
|
+
| Method/Property | Description |
|
|
96
|
+
| ---------------------------------------------------- | ----------------------------------------------- |
|
|
97
|
+
| `readonly source: string` | The original source string |
|
|
98
|
+
| `readonly generatedOffset: number` | Current output position |
|
|
99
|
+
| `write(text: string)` | Emit text to the output |
|
|
100
|
+
| `writeMapped(text: string, srcStart, srcEnd, data?)` | Emit text to the output with mappings |
|
|
101
|
+
| `writeNode(node)` | Dispatch to a printer (preserving if untouched) |
|
|
102
|
+
| `writeNodeList(nodes, sep)` | Print a list with explicit separator |
|
|
103
|
+
| `writeNodeListWithSourceGaps(nodes, fallbackSep)` | Print a list, copying source gaps between nodes |
|
|
104
|
+
| `writeSource(start, end, data?)` | Copy source range and add mapping |
|
|
105
|
+
| `writePreservedNode(node)` | Force-preserve a node from source |
|
|
106
|
+
| `appendMapping(srcRange, genStart, genEnd, data)` | Append a mapping manually |
|
|
107
107
|
|
|
108
108
|
### Exported helpers
|
|
109
109
|
|
package/dist/index.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ interface PrinterContext<Data = any> {
|
|
|
90
90
|
writeNode(node: AST.Node | null | undefined): void;
|
|
91
91
|
writeNodeList(nodes: readonly (AST.Node | null | undefined)[], separator: string): void;
|
|
92
92
|
writeNodeListWithSourceGaps(nodes: readonly (AST.Node | null | undefined)[], fallbackSeparator: string): void;
|
|
93
|
-
writeSource(start: number, end: number, data
|
|
93
|
+
writeSource(start: number, end: number, data?: Data): void;
|
|
94
94
|
writePreservedNode(node: AST.Node): void;
|
|
95
95
|
appendMapping(sourceRange: SourceRange, generatedStart: number, generatedEnd: number, data?: Data): void;
|
|
96
96
|
}
|
|
@@ -175,6 +175,7 @@ declare const defaultPrinters: {
|
|
|
175
175
|
ImportDeclaration: typeof printImportDeclaration;
|
|
176
176
|
ImportExpression: typeof printImportExpression;
|
|
177
177
|
ImportSpecifier: typeof printImportSpecifier;
|
|
178
|
+
ImportDefaultSpecifier: typeof printImportDefaultSpecifier;
|
|
178
179
|
ExportNamedDeclaration: typeof printExportNamedDeclaration;
|
|
179
180
|
ExportDefaultDeclaration: typeof printExportDefaultDeclaration;
|
|
180
181
|
ExportAllDeclaration: typeof printExportAllDeclaration;
|
|
@@ -314,6 +315,7 @@ declare function printPropertyDefinition(node: AST.PropertyDefinition | AST.Acce
|
|
|
314
315
|
declare function printMethodDefinition(node: AST.MethodDefinition | AST.TSAbstractMethodDefinition, context: PrinterContext): void;
|
|
315
316
|
declare function printImportDeclaration(node: AST.ImportDeclaration, context: PrinterContext): void;
|
|
316
317
|
declare function printImportExpression(node: AST.ImportExpression, context: PrinterContext): void;
|
|
318
|
+
declare function printImportDefaultSpecifier(node: AST.ImportDefaultSpecifier, context: PrinterContext): void;
|
|
317
319
|
declare function printImportSpecifier(node: AST.ImportSpecifier, context: PrinterContext): void;
|
|
318
320
|
declare function printExportNamedDeclaration(node: AST.ExportNamedDeclaration, context: PrinterContext): void;
|
|
319
321
|
declare function printExportDefaultDeclaration(node: AST.ExportDefaultDeclaration, context: PrinterContext): void;
|
package/dist/index.js
CHANGED
|
@@ -161,6 +161,7 @@ const defaultPrinters = {
|
|
|
161
161
|
ImportDeclaration: printImportDeclaration,
|
|
162
162
|
ImportExpression: printImportExpression,
|
|
163
163
|
ImportSpecifier: printImportSpecifier,
|
|
164
|
+
ImportDefaultSpecifier: printImportDefaultSpecifier,
|
|
164
165
|
ExportNamedDeclaration: printExportNamedDeclaration,
|
|
165
166
|
ExportDefaultDeclaration: printExportDefaultDeclaration,
|
|
166
167
|
ExportAllDeclaration: printExportAllDeclaration,
|
|
@@ -829,7 +830,7 @@ function printImportDeclaration(node, context) {
|
|
|
829
830
|
}
|
|
830
831
|
let wroteDefault = false;
|
|
831
832
|
for (const s of specifiers) if (s.type === "ImportDefaultSpecifier") {
|
|
832
|
-
context.writeNode(s
|
|
833
|
+
context.writeNode(s);
|
|
833
834
|
wroteDefault = true;
|
|
834
835
|
}
|
|
835
836
|
let namespaceSpec;
|
|
@@ -865,6 +866,9 @@ function printImportExpression(node, context) {
|
|
|
865
866
|
}
|
|
866
867
|
context.write(")");
|
|
867
868
|
}
|
|
869
|
+
function printImportDefaultSpecifier(node, context) {
|
|
870
|
+
context.writeNode(node.local);
|
|
871
|
+
}
|
|
868
872
|
function printImportSpecifier(node, context) {
|
|
869
873
|
if (node.importKind === "type") context.write("type ");
|
|
870
874
|
if (node.local.type === "Identifier" && node.imported.type === "Identifier" && node.local.name !== node.imported.name) {
|
|
@@ -1474,7 +1478,7 @@ function createPrinterContext(options) {
|
|
|
1474
1478
|
appendMapping({
|
|
1475
1479
|
start,
|
|
1476
1480
|
end
|
|
1477
|
-
}, generatedStart, generatedOffset, data);
|
|
1481
|
+
}, generatedStart, generatedOffset, data ?? getMappingData(null));
|
|
1478
1482
|
},
|
|
1479
1483
|
writePreservedNode(node) {
|
|
1480
1484
|
const range = getNodeRange(node);
|