espolar 0.1.3 → 0.1.5

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 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 | 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
- | `writeNode(node)` | Dispatch to a printer (preserving if untouched) |
101
- | `writeNodeList(nodes, separator)` | Print a list with explicit separator |
102
- | `writeNodeListWithSourceGaps(nodes, fallbackSeparator)` | Print a list, copying source gaps between nodes |
103
- | `writePreservedNode(node)` | Force-preserve a node from source |
104
- | `writeSource(start, end, data)` | Copy source range and add mapping |
105
- | `getLeadingComments(node)` | Query leading comments |
106
- | `getTrailingComments(node)` | Query trailing comments |
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: Data): void;
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.local);
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) {
@@ -1411,7 +1415,7 @@ function createPrinterContext(options) {
1411
1415
  generatedOffset += text.length;
1412
1416
  },
1413
1417
  writeMapped(text, sourceStart, sourceEnd, data) {
1414
- if (text.length === 0 || sourceEnd <= sourceStart) return;
1418
+ if (text.length === 0 || sourceEnd < sourceStart) return;
1415
1419
  const generatedStart = generatedOffset;
1416
1420
  context.write(text);
1417
1421
  appendMapping({
@@ -1468,13 +1472,13 @@ function createPrinterContext(options) {
1468
1472
  }
1469
1473
  },
1470
1474
  writeSource(start, end, data) {
1471
- if (end <= start) return;
1475
+ if (end < start) return;
1472
1476
  const generatedStart = generatedOffset;
1473
1477
  context.write(options.source.slice(start, end));
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "espolar",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {